简体   繁体   English

邮件不会被php发送

[英]Mails not getting sent by php

I have a simple script that works fine on any of my other servers, but on that one I need, it doesn't... 我有一个简单的脚本可以在我的任何其他服务器上正常工作,但在我需要的那个,它不...

    <?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>";
?>

When I try to submit contact details through form, it gives an error 当我尝试通过表单提交联系人详细信息时,会出错

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

Although the same script works fine on other servers... Plz Help 虽然相同的脚本在其他服务器上工作正常... Plz帮助

Try this one: 试试这个:

<?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' ;

?>

Even if its not working in your server, you can try sendmail or Swiftmailer. 即使它不能在您的服务器上运行,您也可以尝试使用sendmail或Swiftmailer。 Check the below link: 请查看以下链接:

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

Your server mail sending settings are not configured.check the server mail sending settings and enable all email sending settings of server.Another way is send mail using smtp.Sample code will look like: 您的服务器邮件发送设置未配置。检查服务器邮件发送设置并启用服务器的所有电子邮件发送设置。另一种方法是使用smtp发送邮件。示例代码如下所示:

  1. Your config array settings. 您的配置数组设置。

     $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_timeout'=>'30', 'smtp_user' => 'your_gmail_account@gmail.com', 'smtp_pass' => 'your gmail password', 'mailtype' => 'html', 'charset' => 'iso-8859-1', '_smtp_auth' => TRUE, 'newline' => "\\r\\n" ); 
  2. Initialize that config settings and then use mail sending code. 初始化该配置设置,然后使用邮件发送代码。

It seems sendmail is not configured in this server. 似乎sendmail未在此服务器中配置。 Please ask IT guys to install & configure it for you. 请让IT人员为您安装和配置它。 Unless mail server is not running you would not be able to send email. 除非邮件服务器没有运行,否则您将无法发送电子邮件。 In addition, using gmail or other as SMTP provider will work for testing purpose. 此外,使用gmail或其他作为SMTP提供程序将用于测试目的。 With high volume of emails, I guess they would blacklist your IP. 随着大量的电子邮件,我猜他们会将您的IP列入黑名单。

i also had the same problem. 我也有同样的问题。 So i switched over to PHPMailer library. 所以我切换到了PHPMailer库。 You can user that. 你可以用它。 That will be helpful even sending images. 即使发送图像也会有所帮助。 You can find the PHPMailer document and example code here. 您可以在此处找到PHPMailer文档和示例代码。

http://phpmailer.worxware.com/index.php?pg=examples http://phpmailer.worxware.com/index.php?pg=examples

If this is a Linux server, we have installed mailx before, which then allowed the PHP mail() tag to be used. 如果这是一个Linux服务器,我们之前安装了mailx,然后允许使用PHP mail()标记。

Also, PHPMailer (as mentioned above) is another great suggestion, utilizing SMTP to remote servers. 另外,PHPMailer(如上所述)是另一个很好的建议,利用SMTP到远程服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM