我有一个简单的脚本,可以在我的任何其他服务器上正常工作,但在我需要的那台服务器上,它不...
<?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。检查以下链接:
关于php - php 不发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30522453/