mail()函數在我的服務器上不起作用。我已經使用基本的郵件()代碼來了解它是否存在腳本問題。它仍然沒有發送電子郵件。有人建議我改變我的服務器上的設置以啓用mail()函數或類似的東西。mail()函數無效 - 如何解決?
我該怎麼做?我怎麼知道我的服務器允許mail()或者它正確運行mail()?
有什麼建議嗎?
mail()函數在我的服務器上不起作用。我已經使用基本的郵件()代碼來了解它是否存在腳本問題。它仍然沒有發送電子郵件。有人建議我改變我的服務器上的設置以啓用mail()函數或類似的東西。mail()函數無效 - 如何解決?
我該怎麼做?我怎麼知道我的服務器允許mail()或者它正確運行mail()?
有什麼建議嗎?
如果您使用phpmailer
庫,則無法使用mail()
。因爲它具有預定義的功能。您可以通過訪問PhpMailer Example Page進行檢查。
PHPMailer的使用
$mail->Send()
代替mail()
PHPMailer的
的示例代碼require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo("[email protected]","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address, "John Doe");
$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
使用phpmailer解決了這個問題,謝謝 – 2016-09-05 05:35:31
@SaifudheenMak高興地幫助:) – 2016-09-05 05:36:00
如果您位於共享服務器上,我建議您在他們負責的情況下與他們聯繫。如果它發送電子郵件之前它可能會導致,你可能需要改變你的代碼。 你沒有提供任何樣本代碼,但這裏是我的,試試吧:
$to= "$confoemail";
$subject="Your Contact Request at somewebsite.Com";
$message= "the message to send";
$headers = 'MIME-Version: 1.0' . "\r\n".
'Content-type: text/html; charset=iso-8859-1' . "\r\n".
'From: [email protected]' . "\r\n" . //that code here //perfectly works, search if the code is built -in of php.
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to,$subject, $message, $headers);
,你運行的是什麼操作系統?
在Ubuntu上,您可能會嘗試安裝郵件服務器(postfix或sendmail)。
apt-get install postfix
測試這對你的主機,如果它不工作,你的主機具有郵件禁用。大多數免費服務都會阻止。給我發一個免費的小型主機進行ur測試。
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];;
$subject = $_POST['subject'];
$message = $_POST['message'];
$name = "somename"; $email="[email protected]"; $phone="1111111111" $subject="test"; $message="the message";
$to = '[email protected]';
$subject = 'Message From Website';
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$themessage = "Name: ".$name."</br>Email: ".$email."</br>Phone: ".
$phone."</br>Subject: ".$subject.
"</br>Message: ".$message;
//echo $themessage;
mail($to, $subject, $themessage, $headers);
你檢查了你的垃圾郵件文件夾嗎? – 2013-05-04 05:41:36
你可以發佈你的代碼嗎? – msturdy 2013-05-04 12:15:58