PHP 用mail()發郵件始終不成功。該怎麼解決

來源:互聯網
上載者:User
PHP 用mail()發郵件始終不成功。

$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From: $from";
$send=mail($to,$subject,$message,$headers);
if($send)
echo "Mail Sent";
else
echo "Sorry,mail sent failed!"

?>


開發環境用的wamp,下載並安裝好了sendmail程式,按網上的說法也改好了php.ini和sendmail.ini
使用foxmail 7.1建立了自己QQ郵箱的賬戶,開啟了POP3/SMTP服務。更改發件伺服器為POP3,使用和收件伺服器相同的身分識別驗證。結果還是報錯:Warning: mail(): SMTP server response: 503 Error: need EHLO and AUTH first ! in F:\PHP\wamp\www\mail.php on line 8
不知道哪個地方不對,請會的人指教下。謝謝!!!
mail() sendmail QQ郵箱

分享到:


------解決方案--------------------
可以嘗試phpmailer


$path = realpath(dirname(__FILE__)).'/../libraries/Mail.php';
include("$path");;

$mail= new Mail(); //建立新物件
$mail->IsSMTP(); //設定使用SMTP方式寄信
$mail->SMTPAuth = true; //設定SMTP需要驗證
$mail->SMTPSecure = "ssl"; // Gmail的SMTP主機需要使用SSL連線
$mail->Host = "smtp.gmail.com"; //Gamil的SMTP主機
$mail->Port = 465; //Gamil的SMTP主機的SMTP埠位為465埠。
$mail->CharSet = "UTF-8"; //設定郵件編碼

$mail->Username = "[email protected]"; //設定驗證帳號
$mail->Password = "abcde"; //設定驗證密碼

$mail->From = "[email protected]"; //設定寄件者信箱
$mail->FromName = "工作人員"; //設定寄件者姓名

$mail->Subject = "PHPMailer 測試信件"; //設定郵件標題
$mail->Body = "你好";
//設定郵件內容
$mail->IsHTML(true); //設定郵件內容為HTML
$mail->AddAddress($this->input->post('backemail'), $value->username); //設定收件者郵件及名稱

if(!$mail->Send()) {
echo 'ok';
}

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.