PHP 用mail()发邮件始终不成功。
<?php
$to = "757006080@qq.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "757006080@qq.com";
$headers = "From: $from";
$send=mail($to,$subject,$message,$headers);
if($send)
echo "Mail Sent";
else
echo "Sorry,mail sent failed!"
?>
$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 = "onlyfortestlzz@gmail.com"; //設定驗證帳號
$mail->Password = "abcde"; //設定驗證密碼
$mail->From = "onlyfortestlzz@gmail.com"; //設定寄件者信箱
$mail->FromName = "工作人員"; //設定寄件者姓名
$mail->Subject = "PHPMailer 測試信件"; //設定郵件標題
$mail->Body = "你好";
//設定郵件內容
$mail->IsHTML(true); //設定郵件內容為HTML
$mail->AddAddress($this->input->post('backemail'), $value->username); //設定收件者郵件及名稱
if(!$mail->Send()) {
echo 'ok';
}