暑假笔记2:PHPMail

WBOY
Lepaskan: 2016-08-08 09:20:10
asal
1115 orang telah melayarinya

<code>在学习Luke Welling与L.Thomson的 《PHP and MySQL Web Development》的第四章时需要创建一个可以发送Email的HTML:
</code>
Salin selepas log masuk

D:\PHPProj\PHPWeb\Class1\1.2\processfeedback.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>

"en-US"</span>>

    <meta charset="<span">"UTF-8">
    <title>Bo<span>b's A P -Feedback Submitted</span>
</title>


    <h1>Feedback submitted</h1>
    <p>U feedback has been sent.</p>

</code>
Salin selepas log masuk

使用mail函数的时候出现了一系列的错误,发现因为没有下载Sendmail所以导致不能使用mail()函数,同时我们要用到smtp服务,还需要class.smtp.php的支持:sendmail下载地址:http://glob.com.au/ ,class.smtp.php下载地址:http://www.phpclasses.org/browse/file/920.html 。
1.D:\PHPProj\php-5.6.10x64\sendmail\sendmail.ini的配置:

<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>
Salin selepas log masuk

2.PHP.ini的配制:

<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>
Salin selepas log masuk

重启httpd,出现mail发送出去但是接收方无法得到的问题,还需要解决:我们又下载了phpmailer类http://sourceforge.net/projects/phpmailer/files/phpmailer-ml/PHPMailer-ML_v1.7.1/尝试通过sock发送邮件,来判断问题是否出在程序本身。

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了暑假笔记2:PHPMail,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan