I have read every example out in the web and I still cant seem to connect to the GMAIL SMTP. Here is the code that I am running:
include("phpMailer/class.phpmailer.php"); // path to the PHPMailer class
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myUsername"; // SMTP username
$mail->Password = "myPassword"; // SMTP password
$mail->SMTPDebug = 1;
$webmaster_email = "webMasterEmail#gmail.com"; //Reply to this email ID
$email="someone#gmail.com"; // Recipients email ID
$name="SomeonesName"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Me";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
I tried setting the port in here and I also have the current set up with the following in the class.smtp.php file:
$host = "ssl://smtp.gmail.com";
$port = 465;
I keep getting the same error and I have made sure that ssl is enabled. The error I get is:
SMTP -> ERROR: Failed to connect to server: No connection could be made because the target machine actively refused it.(10061)
As I mentioned above I had already enabled ssl by getting rid of the ; on the line with php_openssl.dll and restarting Apache. I did some more reading and I found out that some people also had "[PHP_OPENSSL]" before the enabling command. I added it and restarted Apache and everything is working! Thanks for all the comments
In php.ini:
[PHP_OPENSSL]
extension=php_openssl.dll
Related
I have a problem, with my code beneath I get this error message:
Message could not be sent.Mailer Error: SMTP Error: The following recipients failed: !Censored!
I have looked into the Host, Port, Username, Password, Recipient and all is correct, what is the problem? Thank you!
Could you please explain too cuz Im new to PHP-coding
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['amne'];
$message = $_POST['message'];
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = '!Censored!'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '!Censored!'; // SMTP username
$mail->Password = '!Censored!'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = $email;
$mail->FromName = $name;
$mail->addAddress('!Censored!'); // Add a recipient
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody = $message;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
EDIT: I found the problem, the problem was not in the php code itself. It was in the contact form. The problem started when I put the variables as names and emails. If the email is not verified, it does not work.
This error can be caused by a few different things. You can get a better idea of the reason by adding the following line to your PHPMailer script:
$mail->SMTPDebug = 2; //<-- For debugging
Once you do that, you can check the following things that may be causing the error:
1.) A corrupt class.phpmailer.php file.
2.) The error may be caused by protection put in place by your ISP. Check with them.
3.) It could be a problem with the recipient's/sender's email addresses.
4.) Set SMTPAuth to true for PHPMailer class.
5.) Comment out the following line in your PHPMailer script: $mail->isSMTP();
Mostly, There is possibility that Your phpmailer class file is corrupted.
Download the latest version: https://github.com/PHPMailer/PHPMailer
I am trying code in php to send mail using SMTP.I am using xampp server to run php code. I am sending mail from neelabhsingh1986#gmail.com to neelabhsingh1000#gmail.com. I got the php code from this site and github. But I am getting message like
SMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
Php code to send mail
<?php
require("D:xampp/htdocs/PHPMailer_5.2.0/class.PHPMailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "neelabhsingh1986#gmail.com"; // SMTP username
$mail->Password = "mypassword"; // SMTP password
$mail->From = "neelabhsingh1986#gmail.com";
$mail->FromName = "Neelabh Singh";
$mail->AddAddress("neelabhsingh1000#gmail.com"); // name is optional
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
In my setup I also have this:
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
Note that you will probably need to authorise this action on your account. You'll get an email from gmail with a link.
This the answer for my post. Please see the link. Download PHPMailer_5.2.0.zip and unzip. I am using xampp server and I created folder in D:\xampp\htdocs\ with name phpMail. I copied these two files(class.phpmailer.phpclass.smtp.php ) from PHPMailer_5.2.0 to phpMail. Now make file sendMail.php and paste following code.
<?php
require("class.PHPMailer.php");
$mail = new PHPMailer();
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "yourEmailAddress#gmail.com"; // SMTP username, sender email address
$mail->Password = "yourGmailPassword"; // SMTP password
$mail->From = "yourEmailAddress#gmail.com";
$mail->FromName = "YourName";
$mail->AddAddress("Receiver#gmail.com"); // Write the email of receiver. Who will get the mail.
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
After writing the code your have to run server. In My case It was http://localhost/phpMail/sendMail.php. When You run this code from browser the you will get one mail regarding this app like Google Account: access for less secure apps has been enabled. When you click this link they asked for permission, Access for less secure apps click yes if you want. Thanks to #rjdown for help.
I have a PHPMailer script, and I've checked all the other threads that are similar to this, and tried all the solutions that follow the question. But here's the error I'm receiving
2014-01-03 02:25:16 SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Mailer Error: SMTP connect() failed.
And here's my script:
$body = "test";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // I have also tried tls
$mail->SMTPKeepAlive = true;
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // I have also tried 25
$mail->Username = "xxxx#gmail.com"; // GMAIL username
$mail->Password = "xxxxx"; // GMAIL password
$mail->SetFrom("johndoe#gmail.com","John Doe");
$mail->AddReplyTo("johndoe#gmail.com","John Doe");
$mail->Subject = "Booking from " . $_POST['person'] . ' at ' . $_POST['name'];
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "johndoe#hotmail.co.uk";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
However I just cannot get it to work. I've tried to many different solutions. I'm even happy to use the default php mail however I just need it to send, the php mail wouldn't even get past the hotmail spam filters (by that I mean it didn't even send it to spam).
Any solutions or suggestions here? Thanks a lot!
Just comment this line:
$mail->IsSMTP();
Did you make sure your php.ini mail settings are the same on both your live server and your localhost server?
Install PHP Mailer From
https://github.com/Synchro/PHPMailer
And Read "A Simple Example"
<?php
require_once('PHPMailer/PHPMailerAutoload.php'); // Load your PHPMailerAutoload.php Correctly Here
$mail = new PHPMailer;
//$mail->SMTPDebug = 3;// debugging: 1 = errors and messages, 2 = messages only // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'yourmail#gmail.com'; // SMTP username
$mail->Password = '**********'; // SMTP password
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // or 587 // TCP port to connect to
$mail->setFrom('fromemail#gmail.com', 'Vijay Rami');
$mail->addAddress('toemail#gmail.com', 'Vijay Rami'); // Add a recipient
//$mail->addAddress('ellen#example.com'); // Name is optional
//$mail->addReplyTo('info#example.com', 'Information');
//$mail->addCC('cc#example.com');
//$mail->addBCC('bcc#example.com');
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
can anyone provide me the way of sending mail through php with attached object as well .plz i am new in this kindly help me in this. is there any server to be installed for this? the mail should this on any email account aswell plz help me in this.can any one provide me the link of tutorial i used the tutorial HERE it display me the error Fatal error: Call to undefined function IsSMTP() in C:\wamp\www\EMS3\mail.php on line 13 plz help me in this
There is an error in the example provided there. Use the following code.
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "username#gmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$webmaster_email = "username#doamin.com"; //Reply to this email ID
$email="username#domain.com"; // Recipients email ID
$name="name"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Webmaster";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
$mail->IsHTML(true); // send as HTML
$mail->Subject = "This is the subject";
$mail->Body = "Hi,
This is the HTML BODY "; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>
update you also need to set the external SMTP server your using. if your using google. i believe its smtp.gmail.com
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Secure = "ssl";
You can use an external PHP library for sending mail, which I have used internally on a localhost, but still configured the parameters to send to external sources. The package is Swift Mailer.
In localhost you can't send any mail. After hosting only this is possible.
I have created a web application in php . I am using PHP Mailer 5.20 class. it work fine when I use XAMPP server on my local server but when we host it on a web-server and try to send a email the it return an error i show you the error below
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
SMTP Error: Could not connect to SMTP host.
I tried all configuration and check all but I receive the same error on the screen.
My PHP mailer class is below
<?php require("PHPMailer_5.2.0/class.phpmailer.php");
function send_email($tomail,$message,$subject)
{
//$dbObj = new Database();
//$dbObj->connect_db();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.mail.yahoo.com"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
/////////////////////////////////( USER NAME AND PASSWORD )/////////////////////////////
$email = "xyxxxxx#yahoo.in";
$mail->Username = $email; // SMTP username
$mail->Password ="xxxxxx"; // SMTP password
$mail->From = $email;
$mail->AddAddress($tomail, $tomail);
// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->AltBody =$message;
$mail->Subject = $subject;
$mail->FromName ="xyz (Online Booking Info)";
if(!$mail->Send())
{ $rr= $mail->ErrorInfo;
exit;
}
}
?>
Can some body tell me where am I wrong or miss configuration?