首頁  >  文章  >  後端開發  >  暑假筆記2:PHPMail

暑假筆記2:PHPMail

WBOY
WBOY原創
2016-08-08 09:20:101119瀏覽

<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>

使用mail函數的時候出現了一系列的錯誤,發現因為沒有下載Sendmail所以導致不能使用mail()函數,同時我們還要用到smtp服務,發現因為沒有下載Sendmail所以導致不能使用mail()函數,同時我們還要用到smtp服務,需要class.smtp.php的支援:sendmail下載網址:http://glob.com.au/ ,class.smtp.php下載網址:http://www.phpclasses.org/browse/file/920.html 。
1.D:PHPProjphp-5.6.10x64sendmailsendmail.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>

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>

重啟httpd,出現郵件發送出去但是接收方無法得到的問題,還需要解決:我們又下載了phpmailer類別http://sourceforge.net/projects/phpmailer/files/phpmailer-ml/PHPMailer-ML_v1.7.1/嘗試透過sock傳送郵件,來判斷問題是否出在程式本身。

版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。

以上就介紹了暑假筆記2:PHPMail,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn