Mail not sending php

I have a simple script that works fine on any of my other servers, but on the 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 via the 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

+3


source to share


5 answers


Try the following:

<?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 it doesn't work on your server, you can try sendmail or Swiftmailer. Check the link below:

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

0


source


Server mail sending settings are not configured. Check the mail sending settings on the server and enable all mail sending settings on the server. Another way is to send mail using smtp.Sample the code will look like this:



  • Settings for your config array.

    $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"
    );
    
          

  • Initialize these configuration settings and then use the mail sending code.

0


source


It seems sendmail is not configured on this server. Ask the IT guys to install and configure it for you. If your mail server is down, you won't be able to send email. Also, using gmail or another as an SMTP provider will work for testing purposes. With a lot of email messages, I think they will blacklist your IP.

0


source


I had the same problem too. So I switched to PHPMailer library. You can use this. It will be useful even for sending images. You can find the PHPMailer doc and sample code here.

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

0


source


If this is a Linux server, we installed mailx earlier, which allowed the PHP mail () tag to be used.

Also, PHPMailer (as mentioned above) is another great offering that uses SMTP for remote servers.

0


source







All Articles