[英]mail() function not working - How to resolve it?
mail()函數在我的服務器上不起作用。 我已經使用了基本的mail()代碼來了解它是否存在腳本問題。 它仍然沒有發送電子郵件。 有人建議我更改服務器上的設置以啟用mail()函數或類似的東西。
我怎樣才能做到這一點? 我怎么知道我的服務器允許mail()或它正確運行mail()?
有什么建議?
如果您在共享服務器上,我建議您與他們聯系,如果他們負責。 如果它發送電子郵件之前它可能是您可能導致的,您可能需要更改您的代碼。 你沒有提供任何示例代碼,但這是我的,試試看:
$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: justin@webmasteroutlet.com' . "\r\n" . //that code here //perfectly works, search if the code is built -in of php.
'Reply-To: justin@webmasteroutlet.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to,$subject, $message, $headers);
你在運行什么操作系統?
在ubuntu上,您可能會嘗試安裝郵件服務器(postfix或sendmail)。
apt-get install postfix
如果您使用phpmailer
庫,則無法使用mail()
。 因為它有預定義的功能。 您可以訪問PhpMailer示例頁面來檢查。
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 = "yourname@yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","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 = "whoto@otherdomain.com";
$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!";
}
在你的主機上測試這個,如果它不起作用你的主機已禁用郵件。 哪些大多數免費服務都會阻止。 給我發消息,為我的測試提供免費的小主機。
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];;
$subject = $_POST['subject'];
$message = $_POST['message'];
$name = "somename"; $email="test@test.com"; $phone="1111111111" $subject="test"; $message="the message";
$to = 'info@fullertoncomputerepairwebdesign.com';
$subject = 'Message From Website';
$headers = 'From: info@fullertoncomputerepairwebdesign.com' . "\r\n" .
'Reply-To: info@fullertoncomputerepairwebdesign.com' . "\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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.