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.