I need to send email using Office365 mail server from may webpage where user enters their email address.My configurations are as follows:
require("phpMailer/PHPMailerAutoload.php");
$mail = new PHPMailer(true);
$mail->CharSet = 'UTF-8';
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = trim($username);//username
$mail->Password = trim($password);//password
$mail->SMTPSecure = 'tls';
$fromName = 'Test';
$from = $myemail;
$mail->AddReplyTo($from, $fromName);
$mail->From = $from;
$mail->FromName = $fromName;
$mail->AddAddress($semail);//mail_id which i need to send mail
$mail->WordWrap = 80; // set word wrap
$mail->MsgHTML($_body);
$mail->IsHTML(true); // send as HTML
When I run the page,it gives following error message
Connection: opening
SMTP ERROR: Failed to connect to server:
php_network_getaddresses: getaddrinfo failed:
Name or service not known (0)
SMTP connect() failed.
**Fatal error**: Uncaught exception 'phpmailerException' with message
'SMTP connect() failed.
When I use gmail server configuration details(host:smtp.gmail.com) ,this is working fine.But my client mail server is with Office365.
I have used the ping command in command prompt for the mail server.
ping mail.mailservername.com <enter>
It gives IP address and another address for the above mail address.I have used the new mail address for the host variable. It works
Related
I have develop one application with help of php. I want to integrate Amazon SES Email service for sending email to user when they regiseter on over website. I've tested this on my localhost, it send email with Amazon SES without any issues. But when i publish to my remote web server, it sends error like this:
SMTP -> ERROR: Failed to connect to server: Connection refused (111)
The following From address failed: info#abc.com
I'm using Godaddy email hosting.
This is my simple code
<?php
function Send_Mail($to,$subject,$body)
{
require 'class.phpmailer.php';
$from = "info#abc.com";
$mail = new PHPMailer();
$mail->IsSMTP(true); // SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Mailer = "smtp";
$mail->SMTPSecure = "tls";
$mail->SMTPDebug = 2;
$mail->Host = "email-smtp.us-west-2.amazonaws.com";
$mail->Port = 587;
$mail->Username = "xxx"; // SES SMTP username
$mail->Password = "xxx"; // SES SMTP password
$mail->SetFrom($from, 'From Name');
$mail->AddReplyTo($from,'test');
$mail->Subject = $subject;
$mail->MsgHTML($body);
$address = $to;
$mail->AddAddress($address, $to);
if(!$mail->Send())
echo $mail->ErrorInfo;
else
echo 'Mail Send';
}
?>
I'm using PHPMailer.
But when i upload to my host i get the error SMTP connect() failed.
My environment
1. Server OS:CentOS 7
2. Web Services: XAMPP 5.6.8
3. PHPMailer:5.2.4
this is my code:
<?php
require_once('PHPMailer_old/class.phpmailer.php');
try{
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 1; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl";
$mail->SMTPAutoTLS = false; // close TLS
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "Test#gmail.com"; // GMAIL username
$mail->Password = "Test"; // GMAIpassword
$mail->FromName = "Test Manager";
$mail->From = "Test#gmail.com";
$to = "Test#hotmail.com";
$mail->AddAddress($to);
$mail->Subject = "First PHPMailer Message";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->WordWrap = 80;
$body = "success!";
$mail->MsgHTML($body);
$mail->IsHTML(true);
$mail->Send();
echo "Message has been sent.";
}catch(phpmailerException $e){
echo "Sending Failed";
echo $e -> errorMessage();
}
?>
Error Message In web:
SMTP -> ERROR: Failed to connect to server: (0)
Sending FailedSMTP Error: Could not connect to SMTP host.
Thanks Everyone Help!
My Solution is uninstall XAMPP and respectively install apache, PHP, MySQL
I am using the following code to sent mail for a contact form. The mail works perfectly when using a windows server setup with xampp, but fails in Linux server RHEL 5.
I am getting "SMTP Error: Could not connect to SMTP host". I tried telnet the host from terminal. It is getting connected
public function smtpmailer($to,$cc, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->IsHTML();
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = 'XXX#gmail.com';
$mail->Password = 'XXXXXXXX';
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
$mail->AddCC($cc);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
While Debugging is set to 1 I am getting the following error
SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
SMTP Error: Could not connect to SMTP host.
Seems as if name resolving is not working. Check /etc/resolv.conf, it should contain a line like this:
nameserver 8.8.8.8
Replace 8.8.8.8 by the IP of your desired nameserver.
I have a server with mail support, say example.com. I configured the server and added MX records via cpanel, so that I can receive and send mails via outlook.com with address myaddr#example.com. The MX records are got from domains.live.com.
Now I need to send mail programmatically using PHP using SMTP. I tried PHPmailer using the following script. But it is showing the error
Mailer Error: SMTP Connect() failed.
(But I can send and receive emails via outlook.com using myaddr#example.com)
$body = $_POST['message'];
$to = "support#example.org";
$from = 'fromAddress#gmail.com';
$fName = 'first name';
$lName = 'last name';
$subject = 'my subject';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
// $body = eregi_replace("[\]",'',$body);
$mail->Host = "mail.example.org"; // SMTP server example
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "myaddr#example.org"; // SMTP account username example
$mail->Password = "password";
$mail->SetFrom($from, $fName.' '.$lName);
$mail->Subject = $subject;
$mail->AddAddress($to, "Support Team");
$mail->MsgHTML($body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
How can I resolve the issue.
Finally I just solved the issue by replacing some of the settings as below and it worked :).
$mail->Host = "smtp-mail.outlook.com"; // SMTP server example
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
I have php code to send email using SMTP connection; It was working perfectly 2 weeks ago. But suddenly stopped working. Don't know what the problem is.
SMTP -> ERROR: FAILED TO CONNECT TO SERVER: A CONNECTION ATTEMPT
FAILED BECAUSE THE CONNECTED PARTY DID NOT PROPERLY RESPOND AFTER A
PERIOD OF TIME, OR ESTABLISHED CONNECTION FAILED BECAUSE CONNECTED
HOST HAS FAILED TO RESPOND. (10060) SMTP ERROR: COULD NOT CONNECT TO
SMTP HOST.
//start mailing function
require_once('PHPMailer_v5.1\class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
//MAIL config
$mail->SMTPAuth = true;
$mail->SMTPDebug = 1;
$mail->Host = "localhost"; // set as the SMTP server
$mail->Port = 25;
$mail->Username = "myemail#web.com"; // localhost email username
$mail->Password = "XXXX";
//End mail config
$mail->From = $sender_email;
$mail->FromName = $sender_user_name;
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->AddAddress($to,$to_name);
$mail->IsHTML(true); // send as HTML
if(!$mail->Send()) {//to see if we return a message or a value bolean
echo "<p>Confirmation Mail delivery failed due to invalid email specified !</p>";
}
It was due to
$mail->Host = "localhost"; // set as the SMTP server
I changed it to
$mail->Host = "mail.web.com"; // set as the SMTP server
It works now!