Home >Backend Development >PHP Tutorial >Summer vacation notes 2: PHPMail
<code>在学习Luke Welling与L.Thomson的 《PHP and MySQL Web Development》的第四章时需要创建一个可以发送Email的HTML: </code>
D:PHPProjPHPWebClass11.2processfeedback.php
<code><span><?php</span><span>$name</span>=addslashes(trim(<span>$_POST</span>[<span>'name'</span>])); <span>$email</span>=addslashes(trim(<span>$_POST</span>[<span>'email'</span>])); <span>$feed</span>=addslashes(trim(<span>$_POST</span>[<span>'feedback'</span>])); <span>$toaddress</span>=<span>"532968708@qq.com"</span>; <span>$subject</span>=<span>"Feedback from web site"</span>; <span>$mailcontent</span>=<span>"Customer name :"</span>.<span>$name</span>.<span>"\n"</span>. <span>"Customer email :"</span>.<span>$email</span>.<span>"\n"</span>. <span>"Customer comments:\n"</span>.<span>$feedback</span>.<span>"\n"</span>; <span>$fromaddress</span>=<span>"From:myphp_test@sina.com"</span>; <span>$issend</span>=mail(<span>$toaddress</span>,<span>$subject</span>,<span>$mailcontent</span>,<span>$fromaddress</span>); <span>if</span>(<span>$issend</span>) { <span>echo</span><span>'<br /> sucessful <br />'</span>; }<span>else</span> { <span>echo</span><span>'<br /> failed <br />'</span>; } <span>?></span> <!DOCTYPE HTML> <html lang=<span>"en-US"</span>> <head> <meta charset=<span>"UTF-8"</span>> <title>Bo<span>b's A P -Feedback Submitted</title> </head> <body> <h1>Feedback submitted</h1> <p>U feedback has been sent.</p> </body> </html></span></code>
A series of errors occurred when using the mail function. It was found that the mail() function could not be used because Sendmail was not downloaded. At the same time, we need to use the smtp service, and Requires support for class.smtp.php: sendmail download address: http://glob.com.au/, class.smtp.php download address: http://www.phpclasses.org/browse/file/920.html.
1.D:PHPProjphp-5.6.10x64sendmailsendmail.ini configuration:
<code>smtp_server=smtp.sina.com smtp_port=<span>25</span> smtp_ssl=SSL pop3_server=pop.sina.com pop3_username=myphp_test<span>@sina.com</span> pop3_password=PW force_sender=myphp_test<span>@sina.com</span></code>
2.PHP.ini preparation:
<code>SMTP = smtp.sina.com ; http://php.net/smtp-port smtp_port = <span>25</span>; For Win32 only. ; http://php.net/sendmail-<span>from</span> sendmail_from = myphp_test<span>@sina.com</span> sendmail_path = <span>"D:/PHPProj/php-5.6.10x64/sendmail/"</span></code>
Restart httpd, there is a problem that the mail is sent but the recipient cannot get it, and it needs to be solved: we download it again Use the phpmailer class http://sourceforge.net/projects/phpmailer/files/phpmailer-ml/PHPMailer-ML_v1.7.1/ and try to send emails through sock to determine whether the problem lies in the program itself.
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the summer vacation notes 2: PHPMail, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.