hello friends after a long time i'm going to post a simple yet useful post here about SMTP mails, i received few email requests from my readers to post email verification feature in my login and registration tutorial i'll post email verification tutorial after this post this was first step to send emails from localhost and online server as well for that you have to use PHPMailer library, so take a quick a look at this tutorial to understand "how to send SMTP mails using PHPMailer"
First of all download the PHPMailer library from this link : http://sourceforge.net/projects/phpmailer/
here using this simple script you can send emails, try it in your localhost server, but make sure that you are connected to the internet
First of all download the PHPMailer library from this link : http://sourceforge.net/projects/phpmailer/
Simple PHP CODE
copy-paste the following script using your editor and save this file as "sendmail.php" and try it in your localhost server
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->CharSet = "utf-8";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "your_gmail_password";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
$mail->setFrom('[email protected]', 'your name');
$mail->AddAddress('[email protected]', 'receivers name');
$mail->Subject = 'using PHPMailer';
$mail->IsHTML(true);
$mail->Body = 'Hi there ,
<br />
this mail was sent using PHPMailer...
<br />
cheers... :)';
if($mail->Send())
{
echo "Message was Successfully Send :)";
}
else
{
echo "Mail Error - >".$mail->ErrorInfo;
}
?>
That's ithere using this simple script you can send emails, try it in your localhost server, but make sure that you are connected to the internet
Thanks for your tutorial. Please describe where and how to install php mailer both on localhost and a web server.
ReplyDeletedownload the phpmailer library from the above link or download the code which i have given here and then put these files in your "www" directory folder / in online server you can install in your root folder...
DeleteWow nice information and it is very informative.The author clearly describe the topic with good example and languages.Thank you so much for your great sharing.custom essay writing services
ReplyDeleteHello it's very nice but I'm not getting email in my gmail id why? Please help me while signing up it tells SMTP Error: Could not authenticate. Please help me to know how to fix it please sir
ReplyDeletehello nimesh, please check your credentials : email id, password, port no is properly set or not , or make sure that you have not enabled 2-step verification in your gmail id.
DeleteHey, i have the same porblem and i have the info put ok, i tested ssl and tls with all ports.... and not working
Delete" SMTP Error: Could not authenticate. Mail Error - >SMTP Error: Could not authenticate."
ReplyDeletehow to fix this error
hello venkata, please check gmail username, password, and smtp port and try to change SMTPDebug value 0, 1, 2 it will give you error messages with details, and there is no need to do change in phpmailer class
Delete$mail->SMTPDebug = 0;
gmail port is :587 not 465
DeleteYou tell us to download the PHPmailer library then don't tell what to do with it. I'm sorry if I'm being a noob. Where should I place it?
ReplyDeleteyou can put PHPMailer Library in your Projects root folder ....
DeleteSMTP Error: Could not connect to SMTP host >> how to fix this error??/
ReplyDeletehello rana raheel,
Deleteplease check gmail credentials, and smtp port and try to change SMTPDebug value 0, 1, 2 it will give you error messages with details, and there is no need to do change in phpmailer class
$mail->SMTPDebug = 0;
make sure you have not enabled two step verification in your gmail account
Hello Pradeep,
ReplyDeleteThe SMTP error is where I get stuck (like the rest I see)
Can you show me where to put my own gmail adress and which port I should put in?
Is it right to just put $mail->SMTPDebug = 0; in the section below?
$mail = new PHPMailer();
$mail->CharSet = "utf-8";
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "your_gmail_password";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
$mail->setFrom('[email protected]', 'your name');
$mail->AddAddress('[email protected]', 'receivers name');
Thx alot!
hello there, i clearly shows that where to put your gmail credentials ,
Delete$mail->Username = "[email protected]";
$mail->Password = "your_gmail_password";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
$mail->setFrom('[email protected]', 'your name');
$mail->AddAddress('r[email protected]', 'receivers name');
Hi, i'm getting this error. SMTP Error: Could not connect to SMTP host. Mail Error - >SMTP Error: Could not connect to SMTP host.
Deletehow to change gmail smtp to office365 smtp
ReplyDeletesir can u pls tell the configuration for office365 host
ReplyDeletehello himanshu, i found link it might helpful to you
DeleteSMTP , POP, IMAP Details for office 365
No that wasn't i tried that link
ReplyDeleteafter doing some changes its showing these errors
ReplyDeleteSMTP -> FROM SERVER:220 HE1PR03CA0017.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 3 Nov 2015 17:08:37 +0000
SMTP -> FROM SERVER: 250-HE1PR03CA0017.outlook.office365.com Hello [14.139.242.69] 250-SIZE 157286400 250-PIPELINING 250-DSN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 XXXXXXXX
SMTP -> ERROR: AUTH not accepted from server: 504 5.7.4 Unrecognized authentication type
SMTP -> FROM SERVER:250 2.0.0 Resetting
SMTP Error: Could not authenticate
sorry himanshu, i haven't work with office 365 but the concept was the same, so try to solving it, there's must be something wrong within authentication. or if you have office 365 server and your own mail then you can find your smtp details and configurations there in your webmail.
DeleteAm still having issues with STMP host
ReplyDeleteCould not connect to STMP host
Must i be connected to the internet to make it work
ReplyDeleteSTMP could not connect to host
yes, you must be connected to the internet..
DeleteThanks for this guide to using PHPMailer - Certainly the best I've found. I had great issue getting it to work.. I'd checked all the things you mentioned but eventually found that it worked (by sending through my gmail smtp) if I removed the line:
ReplyDelete$mail->IsSMTP();
and if I want to send via localhost, I remove (or comment out lines 8-13.
Hope this help someone :)
I'm using localhost and still not working. I have commented out $mail->IsSMTP(); and line 8-13. The message is being send but not receive by the receipient. Please post the working code.
DeleteRemoved $mail->IsSMTP(); and worked for me. Thanks.
DeleteHello Steven, I removed what you said. It says message was successfully send. but in my email :[email protected] , there is no email.
Deletehow to fix this error
ReplyDeleteCall to undefined method PHPMailer::setFrom()
Hello Pradeep,
ReplyDeleteIs there any other way for email verification than phpmailer.Kindly help.
you can use swiftmailer or sendgrid
DeleteDear Pradeep.
ReplyDeleteIs there any other way for email verification than through phpmailer.Kindly help
I cannot downloading the code plz help me
ReplyDeletedownload link updated, get it from there ...
Delete$mail->AddAddress('[email protected]', 'receivers name');
ReplyDeleteThis is not required for me because the user enter their email address in feed back form and then the message is sent to the admin mail address.
I am working from xampp.It showing the Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. 17sm5260251pfq.51 - gsmtp in.
ReplyDeleteAnd the mail is not sending
Plzzz help me
Hi Pradeep, I added class.phpmailer.php file and got phpmailer to send confirm registration email which lands in my spam atm... but when i follow link to sign in it says wrong details...? I've rechecked what I've typed but still the same. please help
ReplyDelete
ReplyDeleteWarning: require_once(mailer/class.phpmailer.php): failed to open stream: No such file or directory in C:\xampp\xampp\htdocs\tags\Class.User.Php on line 112
Fatal error: require_once(): Failed opening required 'mailer/class.phpmailer.php' (include_path='C:\xampp\xampp\php\PEAR') in C:\xampp\xampp\htdocs\tags\Class.User.Php on line 112
Hi Pradeep,
ReplyDeleteI used the codes from this page, had "HTTP 500 error: can not find the page". I tried to trace the code and found the statement below is the problem
$mail->setFrom([email protected]', 'yyyyyy');
and found that error is caused in the PHPMailer
public function getSMTPInstance()
{
if (!is_object($this->smtp)) {
$this->smtp = new SMTP; //<===== this is where the problem caused
}
return $this->smtp;
}
could you help to figure out what is problem? and give advice. I have class.smtp.php and class.phpmailer.php in the same folder.
Hi Pradeep,
ReplyDeleteI used the codes from this page, had "HTTP 500 error: can not find the page". I tried to trace the code and found the statement below is the problem
$mail->setFrom([email protected]', 'yyyyyy');
and found that error is caused in the PHPMailer
public function getSMTPInstance()
{
if (!is_object($this->smtp)) {
$this->smtp = new SMTP; //<===== this is the problem }
return $this->smtp;
}
could you help to figure out what is problem? and give advice? I have class.smtp.php and class.phpmailer.php in the same folder.
I got this error: Call to undefined method PHPMailer::setFrom(
ReplyDeleteTHANKS this is a good one ! but I have you ever encounter this error from Gmail ? ,
ReplyDeleteEmail From Mail Delivery Subsystem :
Delivery to the following recipient failed permanently:
[email protected]
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for the recipient domain mail.com by mx00.mail.com. .
The error that the other server returned was:
550 Requested action not taken: mailbox unavailable
could you help to figure out what is problem? When i Click HERE to Activate .it shows object not found.
ReplyDeleteThanks for sharing your thoughts & excitements about future of the web. good post guys and thanks for your article this is simply awesome. thanks for your info! json converter
ReplyDeletethank you so much for share the knowledge. It worked like a charm. It worked in the first go with the hosting provider (godaddy). I was very skeptical if this code was kept current or not . But I confirm you guys that as on 23-Mar-2017 - this code works perfectly.
ReplyDeleteThis code worked like a charm. I was skeptical initially but I confirm it works perfect and the code is current as on 23-Mar-2017. Thank you so much for sharing this knowledge. It is very encouraging for hobby learners like myself.
ReplyDelete