php - php 不发送邮件

标签 php email sendmail

我有一个简单的脚本,可以在我的任何其他服务器上正常工作,但在我需要的那台服务器上,它不...

    <?php
$name = $_POST['Name'];
$email = $_POST['Email'];
$phone = $_POST['Phone'];
$message = $_POST['Message'];

$formcontent="Name: $name \n Email: $email \n Phone No: $phone \n Services: $services \n Message: $message";
$recipient = "gaurav.m@momentsworld.com";
$subject = "Client Details";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='../contact.html' style='text-decoration:none;color:#ff0099;'>Return Home</a>";
?>

当我尝试通过表单提交联系方式时,出现错误

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\Inetpub\vhosts\momentsworld.com\httpdocs\script\quick_query.php on line 17

虽然相同的脚本在其他服务器上工作正常......请帮助

最佳答案

试试这个:

<?php
ini_set("SMTP","localhost");
ini_set("smtp_port",25);
ini_set("sendmail_from","sender_mail@gmail.com");

$too = "receiver_mail@yahoo.com" ;
$subject = "TEST" ;
$message = "User message" ;
$user_email = "user_mail@gmail.com" ;

$headers = "From: $user_email " ;
$headers .= "Reply-To: $too " ;
$headers .= "Return-Path: $too " ;
$headers .= "X-Mailer: PHP/" . phpversion (). " " ;
$headers .= 'MIME-Version: 1.0' . " " ;
$headers .= 'Content-type: text/html; UTF-8' . " " ;

if( mail ( $too , $subject , $message , $headers )) echo 'SENT' ;

?>

即使它在您的服务器上不起作用,您也可以尝试使用 sendmail 或 Swiftmailer。检查以下链接:

http://swiftmailer.org/docs/sending.html

关于php - php 不发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30522453/

相关文章:

java - 使用 Java 发送电子邮件

javascript - 无法使用 Cloud Functions for Firebase 发送邮件

email - 使用 ssl 的 Yandex smtp 设置

php - 下滚动后的字符串最后一位数字

php - Mysql 没有按预期返回结果

php - 将 POST 数据从 Objective-C 传递到 PHP

php - 如何获取给定城市/国家的经度/纬度?

c++ - 如何通过C++程序发送Email?

email - 如何从 Go 发送电子邮件

php - 如何发送 debian sendmail 以使用 google Apps smtp 绕过 ISP 阻止 smtp