I am able to send emails to email addresses on the host domain so sending an email to me#domain.com work, where the mail host is domain.com, but if I send it to me#gmail.com it doesn't come through, and I don't get any errors from the phpMailer, with debug on, it shows everything has been done. Here is my phpMailer setup:
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPDebug = 2;
$mail->Host = "mail.mydomain.co.uk"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "sendmail#mydomain.co.uk"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "info#mydomain.com"; //do NOT fake header.
$mail->FromName = "Me";
$mail->AddAddress("you#gmail.com"); // Email on which you want to send mail
$mail->Subject = "Just a Test";
$mail->Body = "Hello. I am testing <b>PHP Mailer.</b>";
if(!$mail->Send()){
echo $mail->ErrorInfo;
}else{
echo "<p>Thank you, we will be in touch shortly</p>";
}
What is going on? As far as the mailer is concerned it has sent because I get back
SMTP -> FROM SERVER:250 Requested mail action okay, completed
SMTP -> FROM SERVER:250 Requested mail action okay, completed
SMTP -> FROM SERVER:354 Start mail input; end with .
SMTP -> FROM SERVER:250 Requested mail action okay, completed
Related
I'm trying to learn PHPMailer and I don't understand why it needs an email address and password.
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
It's not coming from a persons email, it's coming from the site. What email am I supposed to put here and why?
The email address is the address which the emails are sent from. The username and password are required for SMTP servers that require authentication in order to send mail.
The way email works is that party 1 has an email account which it uses to send mail to party 2. Party 1 can be a site, a person, a script or something else, but it still needs to have an email account to be able to send email.
This is the way SMTP (Simple Mail Transfer Protocol) has been defined, and you need to follow the definitions of that protocol to get your mail delivered.
It is not necessary to provide password -
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "smtp.example.com"; // SMTP server
$mail->From = "example#gmail.com";
$mail->AddAddress("example#gmail.com");
$mail->Subject = "First PHPMailer Message";
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
Click here
I want to send a confirmation mail to an user who is trying to register. Iam using PHP Mailer for sending mails. Here is my code:
require_once("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "root";// SMTP username
$mail->Password = "";// SMTP password
$mail->SetLanguage("en","PHPMailer/language");
//compose mail
$mail->From = "admin#localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin#localhost.com", "Cinema Admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/user.login_plugin/confirm.php?passkey=$confirm_code";
//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
When I execute the file,it says
Message was not sent
Mailer Error: SMTP connect() failed.
Could anyone suggest me for sending mails from localhost to the registered user's emailid.
I had searched with few titles regarding "ending emails" in stack overflow, but couldn't find any solution from any posts.
Thank You in advance
Could you try remove the smtp part? From your comment , you do not have mail server setup.
$mail = new PHPMailer();
$mail->SetLanguage("en","PHPMailer/language"); // remove smtp things
You must need a SMTP details in order to send an email using SMTP, For example if you want to setup SMTP using gmail,
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername#gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
If you don't want use SMTP, you can called default mail function
$mail->IsMail(); //Sets Mailer to send message using PHP mail() function.
so i have been working with gmail and using php mailer and it was working fine.
i tried to do the same with yahoo mail but it doent seem to work.
i have tried various ports and settings but it isnt working.
here is the code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PHPMailer - GMail SMTP test</title>
</head>
<body>
<?php
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require 'phpmailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.mail.yahoo.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587; //995 and 465 port tried but not working
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tsl';//only ssl tried not working
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "sender#yahoo.com";
//Password to use for SMTP authentication
$mail->Password = "sender_pass";
//Set who the message is to be sent from
$mail->setFrom('sender_#yahoo.com', 'sender_name');
//Set who the message is to be sent to
$mail->addAddress('receiver#yahoo.com', 'receiver_name');
//Set the subject line
$mail->Subject = 'PHPMailer YMail SMTP test';
$mail->msgHTML(file_get_contents('phpmailer/examples/contents.html'), dirname(__FILE__));
$mail->AltBody = 'This is a plain-text message body';
$mail->addAttachment('phpmailer/examples/images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
and i get the following error:
SERVER -> CLIENT: 220 smtp.mail.yahoo.com ESMTP ready
CLIENT -> SERVER: EHLO localhost
CLIENT -> SERVER: AUTH LOGIN
SERVER -> CLIENT: 530 5.7.0 Must issue a STARTTLS command first
CLIENT -> SERVER: QUIT
SERVER -> CLIENT: 221 2.0.0 Bye
SMTP connect() failed.
Mailer Error: SMTP connect() failed.
The correct is tls, you have a spell mistake:
$mail->SMTPSecure = 'tls'
2020 - Google brought me here for something similar.
Finally got phpmailer working with yahoo.
My Findings:
* Ports -> Both ssl/465 and tls/587 work with Yahoo. You dont have to
worry about that.
* From Address -> Cannot be something arbitrary, just use your
yahoo account email here
* ReplyTo Address -> This too must be a valid yahoo account
or you may leave this blank.
And ...
for programmatic usage of yahoo with phpmailer, you need to use another passwd ( not the password that you use to login manually via the web - got this tip from a non stackoverflow site, maybe expert xchange? ). This password is called the App Password. You have to generate it from inside your account.
Account Info -> Account Settings -> Manage Your App Passwords
-> Select Other App -> Key in 'AutoMailer'
or anything you like and generate the passwd - Its a 4 word passwd.
Use this passwd in your phpmailer script.
Everything should be fine now.
The yahoo SMTP host is: smtp.mail.yahoo.fr, the port: 465 and SSL is required.
So with PHPMailer:
$mail->Host = "smtp.mail.yahoo.fr, ";
$mail->Username = "youryahooadd#yahoo.fr";
$mail->Password = "youryahoopw";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail = new PHPMailer();
$body = "<h1>hello, world!</h1>"
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.mail.yahoo.com"; // sets YAHOO as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername#gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "whoto#otherdomain.com";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I'm trying to send a message from a script on a site, using SMTP. I can successfully read the mail on my personal email, although my work email does not receive it. I think it might be bouncing.
In the Google admin panel, I have added test.domain.com as an alias for domain.com.
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPDebug = 2;
$mail->From = "smtp#test.domain.co.uk";
$mail->FromName = "No-Reply # Domain";
$to = 'harry#test.domain.co.uk, personalEmail#gmail.com';
$mail->AddAddress('harry#test.domain.co.uk');
$mail->AddAddress('personalEmail#gmail.com');
$mail->AddReplyTo($mail->From, $mail->FromName);
$mail->WordWrap = 80; // set word wrap to 50 characters
$mail->IsHTML(false); // set email format to HTML
$mail->Subject = $subject[PAGE];
$mail->Body = $body;
if ( $mail->Send() )
{
header('location: '.$_SERVER['REQUEST_URI'].'?sent1');
exit;
}
else
{
$errors[] = 'Sorry, your message could not be sent, '.$mail->ErrorInfo;
}
I have created an MX record for test.domain.com as well as an SMTP relay service in Google Admin, as well as allowing per-user outbound gateways (Allow users to send mail through an external SMTP server when configuring a "from" address hosted outside your email domains).
When we set up PHP mailer we need to add the credentials of SMTP mail Server in it.In you code example you skipped those lines and it is ncessary to send an email
mail->Host = "smtp.yourmail.com"; // Your SMTP server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'tls'; //SMTP secure type like ssl/tls
$mail->Username = "dont.reply.m#yourmail.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "dont.reply.m#yourmail.com"; // SMTP username
Please try with proper credentials on the top after initialisation of object $mail
I tried to use php mailer but errors as follows.
SMTP -> FROM SERVER:
SMTP -> FROM SERVER:
SMTP -> ERROR: EHLO not accepted from server:
SMTP -> FROM SERVER:
SMTP -> ERROR: HELO not accepted from server:
SMTP -> ERROR: AUTH not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connectedSMTP Error: Could not authenticate. Message could not be sent.
Mailer Error: SMTP Error: Could not authenticate.
and my code
<?php
require("class.phpmailer.php")
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPDebug = 2;
$mail->Username = "admin#xxxxxxxxxxxx.in";
$mail->Password = "xxxxxxxx";
$mail->From = "admin#xxxxxxxxxxxx.in";
$mail->FromName = "Mailer";
$mail->AddAddress("xxxx#yahoo.co.in", "mine");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$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";
?>
I was getting this due to wrong port for SSL.
SSL = 465
TLS = 587
See:
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287
Some servers (especially shared hosting) will block you from using SSL with SMTP, I had the same problem once.
Either change host if you can, try using the default PHP mail() function or send through another mail server that does not require SSL e.g. port 25 not 465.
Something like AuthSMTP would be your best bet for an alternate mail server.
I had the same problems, it seems that we have
to set the SMPTSecure value.
First I changed the port from 465 to 587 and added:
$mail->SMTPSecure = "tls";
and it worked :)
If you are working in your localhost just go to the PHP Extention and enable or check the php_openssl
it will be able to access the SSL ports.
try this code
require 'PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->IsSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "admin#gmail.com";
//Password to use for SMTP authentication
$mail->Password = "admin123";
$mail->setFrom('admin3#gmail.com', 'development'); //add sender email address.
$mail->addAddress('admins#gmail.com', "development"); //Set who the message is to be sent to.
//Set the subject line
$mail->Subject = $response->subject;
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->Body = 'Name: '.$data['name'].'<br />Location: '.$data['location'].'<br />Email: '.$data['email'].'<br />Phone:'.$data['phone'].'<br />ailment: '.$data['ailment'].'<br />symptoms: '.$data['symptoms'];
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.gif');
//$mail->SMTPAuth = true;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Had the same issue, Change port No in opencart mail setting to 587 and works fine
May be because of fire wall?
If you can't sign in to Google Talk,
or you're receiving an error that
says, Could not authenticate to
server, check if you have personal
firewall software installed, or if
your computer is behind a proxy server
that requires a username and password.
http://www.google.com/support/talk/bin/answer.py?hl=en&answer=30998
I use the same script for several clients and only run into this problem when deploying to Amazon EC2 cloud providers (such as Openshift).
These are tried and tested settings in phpmailer:
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587;
'but' Google blocks these services as an 'anti-spam' / political maneuver, and this has caught me out because it works locally and on most hosting providers, there is nothing much you can do when they don't accept outbound messages from your hosts DNS / IP. Accept it and move on by looking for another smtp server to route messages through.
not sure but try $mail->Host = "smtp.gmail.com" =>$mail->Host = "smtp.google.com"