if(mysql_affected_rows()==1)
{
$msg="To activate your account, please click on the following link:\n\n
http://localhost:80/activate.php?email=".urlencode($email)."&key=".$activation;
if(mail($email,"Registration Confirmation", $msg, "From: [email protected]\r\nX-
Mailer: php"))
{
echo '<div> Thank you for registering. A confirmation email has been sent to '.
$email.'.Please click on the link to activate your account then</div>';
}
}
我使用的代碼片段從[email protected]發送電子郵件至$電子郵件([email protected]),但我沒有收到任何電子郵件的雅虎帳戶。儘管如此,瀏覽器中顯示的回顯消息表明郵件成功。此外,我試圖直接通過Outlook從[email protected]發送電子郵件到雅虎帳戶,它工作正常。請有人幫我修復該源代碼片段或任何類型的額外設置,以使郵件功能的工作?非常感謝。從本地主機到外部電子郵件帳戶發送電子郵件
編輯:順便說一句,我還設置了我的php.ini的STMP腳本塊如下,
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.mycompany.com
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]
我的問題是設置我的本地計算機的本地郵件服務器,我editted PHP。如上所述,但它仍然不起作用。
[解決]
<?php
function SendMail($from, $to, $subject, $body)
{
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.mycompany.com";
$mail->SMTPAuth = true;
$mail->Username = "My name"; // SMTP username
$mail->Password = "mypassword"; // SMTP password = one used in Outlook
$mail->From = "[email protected]";
$mail->FromName = "Registration Confirmation Email";
$mail->AddAddress($to);
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
return false;
}
return true;
}
?>
我包括上面的代碼剪斷證明使用PHPMailer的一個小而工作示例。感謝下面這篇文章中介紹給我的人。
我不知道我可以從本地主機發送郵件! – 2012-02-02 07:59:50
您的代碼是否託管在Windows系統上? – Repox 2012-02-02 08:08:20
您能否提供有關正在發生的事情的更多詳細信息?任何錯誤?任何異常?這對了解您的問題至關重要。 – 2012-02-02 08:09:22