0

I'm trying to send email via mail() function and smtp but it does not work on windows server 2008, I checked same process and code on bluehost server which is working fine.

Mail Function Error

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Alen <example1@gmail.com>' . "\r\n";
$headers .= 'From: john Smith <example2@gmail.com>' . "\r\n";
$message = "
<strong>Hi xyz,  </strong><br />
<p>Your new password is asd,  </p>
";
echo mail('example1@gmail.com', 'Need to CHeck', $message, $headers);

I tried above email function which is giving me following error in error log.

PHP Warning: mail(): Failed to connect to mailserver at "mail.reliedhosting.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in

I tried this answer for resolving my issue but did not resolved.

SMTP Does not Connect

I also tried to connect smtp but it does not connecting.

require 'PHPMailerAutoload.php';
        $mail = new PHPMailer;
        $mail->isSMTP();
        $mail->SMTPDebug = 2;
        $mail->Debugoutput = 'html';
        $mail->Host = "mail.exampleDomain.com";
        $mail->Port = 25;
        $mail->SMTPAuth = true;
        $mail->Username = "info@cms.exampleDomain.ae";
        $mail->Password = "myPassWord";
        $mail->setFrom('info@cms.exampleDomain.ae', 'John');
        $mail->addReplyTo('web@example.com', 'Jimm');
        $mail->addAddress($email, $name);
        $mail->Subject = $subject;
        $mail->msgHTML('<h1>'.$message.'</h1>');
        $mail->AltBody = 'This is a plain-text message body';
        if (!$mail->send()) {
            echo "Mailer Error: " . $mail->ErrorInfo;
        } else {
            echo "Message sent!";
        }

Code is returning following error

SMTP ERROR: Failed to connect to server: The requested address is not valid in its context. (10049) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/TroubleshootingFunction Executed

I have searched for that, according to my research i thought that may be smtp cofiguration is not correct, but when i checked through phpinfo() it showing correct according to this reference.

I'm also attaching a part of phpinfo page, kindly view it. Can any one guide me where is the issue and how can i fix it I would like to highly appreciate. enter image description here

Community
  • 1
  • 1
Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68
  • This is covered in the troubleshooting docs linked from the error; Your mail server (`mail.reliedhosting.com`) is not responding. – Synchro Jul 12 '16 at 13:16
  • Because you included it in your question? – Synchro Jul 12 '16 at 13:21
  • @Synchro so what should i do for resolving my problem – Ayaz Ali Shah Jul 12 '16 at 13:21
  • Fix your mail server, or use one that works. – Synchro Jul 12 '16 at 13:22
  • @Synchro I checked, but i have limited privileges in control panel, so how can i fix can you kindly guide me. – Ayaz Ali Shah Jul 12 '16 at 13:23
  • Sorry, you'll need to ask your hosting provider. – Synchro Jul 12 '16 at 13:24
  • @Synchro Sure, So I will tell them that `mail server does not responding kindly fit the issue`. Am I right ? – Ayaz Ali Shah Jul 12 '16 at 13:25
  • Ask them to confirm the mail server details you need for sending email and use the settings they tell you. They probably have documentation on this already, so check that first. It looks likely that you have the wrong host name, possibly the wrong port number too. – Synchro Jul 12 '16 at 13:30
  • @Synchro I checked port its 25, and they me host name, but i'm not sure its correct or not. Also our code on sub-domain. Thanks You – Ayaz Ali Shah Jul 12 '16 at 13:32
  • Well that host name is not in DNS, so that's clearly wrong. Port 25 is usually only used for inbound SMTP, not outbound - I'd expect you to be using port 587 - see the PHPMailer docs. – Synchro Jul 12 '16 at 13:34
  • @Synchro yes you are saying right, actually my client give me access on sub domain `cms.example.com` and also he send me two url for mail.ONE `mail.reliedhosting.com` and SECOND `mail.cms.example.com`. But these does not working – Ayaz Ali Shah Jul 12 '16 at 13:44
  • @Synchro Thank you so much for your guideline and time – Ayaz Ali Shah Jul 12 '16 at 13:45

0 Answers0