簡體   English   中英

無法使php mail()工作

[英]Can't get php mail() to work

我的Mac上運行了Mamp,並試圖使mail()正常工作。

這就是我要處理的。

$to = 'mymail@gmail.com';
$subject = 'The subject!';
$message = 'Hi there!';


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= "X-Mailer: PHP/".phpversion();
$headers .= 'From: Test <test@test.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


// Mail it
if(mail($to, $subject, $message, $headers))
{ print 'success!'; }
else
{ print 'fail!'; }

?>

它只是不斷返回false。 知道我在做什么錯嗎? 我需要檢查php / apache的一些設置嗎?

如果您在本地主機上使用代碼段,請放在服務器上,然后嘗試。 如果您想運行php mail()函數,則必須將其關閉。 在本地主機上,您總是會失敗!

嘗試這個:

<?php
$Name = "Da Duder"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

ini_set('sendmail_from', 'me@domain.com');

mail($recipient, $subject, $mail_body, $header);
?>

http://be.php.net/manual/zh/function.mail.php

每行文字不得超過70個字符,需要用LF(\\ n)隔開

編輯:如@brad建議:SwiftMailer真的很好!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM