简体   繁体   中英

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

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. Check the below link:

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:

  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. Please ask IT guys to install & configure it for you. 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. With high volume of emails, I guess they would blacklist your IP.

i also had the same problem. So i switched over to PHPMailer library. You can user that. That will be helpful even sending images. You can find the PHPMailer document and example code here.

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.

Also, PHPMailer (as mentioned above) is another great suggestion, utilizing SMTP to remote servers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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