This code is work, email is sent
$mail = new PHPMailer();
$mail->setFrom("name1#gmail.com", "Name");
$mail->addAddress($to); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("name1#yahoo.com", "Reply");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->send())
{
echo 'Mailer Error: ' . $mail->ErrorInfo . "\n";
}
But for some reason, if I change From email to name2#yahoo.com
$mail->setFrom("name2#yahoo.com", "Name");
emails does not sends anymore. Phpmailer does not report any error messages.
name2#yahoo.com is valid working email address related to this web server.
Thanks.
This is covered in the PHPMailer troubleshooting guide.
Most service providers now have strict SPF and DMARC configurations (Yahoo especially, since they invented DMARC) that mean that you cannot send from addresses in their domains except through their own mail servers, or any others included in their SPF records.
Your code is sending through your own local server, which is not a Yahoo server, and thus won't work.
The solution is to send through Yahoo's own servers using authentication for your email account, something like:
$mail->isSMTP();
$mail->Host = 'smtp.mail.yahoo.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Username = 'me#yahoo.com';
$mail->Password = 'password';
Yahoo's DMARC config won't let you spoof the from address, so you can only use a from address that matches your username - this is probably the cause of the symptom you're seeing.
Related
I have 3 mail ids say, user1#abc.com, user2#abc.com and user3#abc.com. I have setup PHPMailer with SMTP user as user1#abc.com. Now I set an auto response to user3#abc.com.
When I send a mail from user2#abc.com to user3#abc.com, autoresponse is going to user1#abc.com, the address i used to configure SMTP. How can I make autoresponse to send to FROM address?
$mail->isSMTP();
$mail->Host = 'hostname';
$mail->SMTPAuth = true;
$mail->Username = 'user1#abc.com';
$mail->Password = 'password';
$mail->SMTPSecure = '';
$mail->Port = 25;
$mail->Sender='user1#abc.com';
$mail->AddReplyTo('user2#abc.com', 'User2');
$mail->setFrom('user2#abc.com', 'User2', FALSE);
$mail->addAddress('user3#abc.com', 'User3');
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $mailBody;
$mail->send();
You have not set a to address, so it's falling back to a default.
$mail->addAddress('user3#abc.com');
Many ISPs (for example gmail) will not allow you to set arbitrary from addresses, so if your from address is not working, check that. Also, be sure not to forge from addresses as it will cause delivery failures when you break SPF rules.
If you're writing an autoresponder, check that the inbound message you're responding to does not have a Precedence: bulk header set; autoresponses should not be sent to mailing lists (which should set that header) as it will often cause loops.
I installed recently PHPMailer, because of not being able to send without it.
Now I have another problem: I want to send an email with an invent one, for example, "no-reply#my-domain.com". I don't seem to be able to do it. when I send with Sendmail, it just won't send, and if I use SMTP with autentication, it sends with my email.
require "../PhpMailer/PHPMailerAutoload.php";
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "marcelo43#gmail.com";
$mail->Password = "My Password";
$mail->setFrom('no-reply#my-domain.com','MyDomain Admin');
$mail->addAddress('to#gmail.com','To');
$mail->Subject = "Test";
$mail->msgHTML('My message');
if(!$mail->send())
echo 'Could not send email';
else
echo 'Email succesfully sent';
This just sends an email to "to#gmail.com" with "MyDomain Admin" as the name and "marcelo43#gmail.com" as its email.
What do I need to do to send with the email "no-reply#my-domain.com"?
You can't send email with a false email because Gmail blocks mail from an other domain that its own.
If you want to send an e-mail with an other domain you should use an other SMTP server. You can use an SMTP from OVH for example if you have a mail server. Otherwise, Yahoo will let you send you e-mail I think.
Gmail doesn't let you use arbitrary from addresses at all, even from gmail domains. You can however create aliases within your gmail settings that are allowed as from addresses. If you want to use your own domain via gmail, you will neeed to configure gmail as the MX for your domain. If you do that, you will be able to do what you ask.
BTW, this is mentioned in the PHPMailer docs.
This question already has answers here:
send email using php
(3 answers)
Closed 6 years ago.
When I execute this code, a new tab is opened. It displays my code. How do I fix this?
<?php
$mail = new PHPMailer();
//Send mail using gmail
if($send_using_gmail){
$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.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "myemailid#gmail.com"; // GMAIL username
$mail->Password = "mypassword"; // GMAIL password
}
//Typical mail data
$mail->AddAddress('myemailid#gmail.com', 'Name');
$mail->SetFrom('myemailid#gmail.com', 'Name');
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
//Something went bad
echo "Fail :(";
}
?>
I am trying to send an email using PHP here.
$mail = new PHPMailer();
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port = 26; // set the SMTP port for the GMAIL server
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
$mail->SetFrom('name#yourdomain.com', 'First Last');
$mail->AddReplyTo("name#yourdomain.com","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication";
$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!";
}
try this one it worked for me. If didnt work let me know
I know this will not answer OP's question but i want to make this in people's attention, Please excuse me...
Source :- https://sendgrid.com/blog/gmail-dmarc-update-2016/
What is Gmail changing?
June of 2016 Gmail will change its DMARC policy from p=”none” to p=”reject.” This means any message sent using gmail.com in the from address, will have to originate from Gmail’s infrastructure.
What does this mean for me?
It depends. If you have any mail streams that send messages using gmail.com in the from address, you will have to make changes before June, or risk having those messages filtered or blocked outright.
If you only send email using your own domain or another domain that you control, you have nothing to worry about. However, it’s not uncommon for some applications or websites to send messages using their users’ email addresses. For example, if a user wants to send a message to their friend using your platform, it could make sense to send the message using their personal email address. If their email address happens to be a gmail.com address, this message will no longer deliver once these changes take place. A good alternative to sending mail from your user’s email address is to use their name in the friendly from. A “friendly from” is when you use a name to appear as the from address, instead of the email address itself:
exampleuser#yahoo.com can be sent as “Example User”
This way your recipients still recognize the individual that sent the message, and you’re no longer at risk of violating Gmail’s DMARC policy.
I do not know if what I want to do is possible (but finding out that it isn't would be useful in itself).
I cannot use my company's gmail account "real.business#gmail.com" directly with PHPMailer. I can, however, use an intermediary gmail account "fake.12345.account#gmail.com" which can have "less secure apps" enabled, which permits SMTP verification.
However I do not want to have the emails be sent from this fake.12345.account#gmail.com account (wouldn't look particularly professional) - but rather the company's gmail account.
I can send the emails from the intermediary account to real.business#gmail.com; either through the editing of the PHPMailer parameters, or by automatically forwarding emails from fake.12345.account#gmail.com to the company account.
The problem lies in how real.business#gmail.com can then successfully email the email (or at least appear to be the sender), as originally intended.
The code so far
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host = "smtp.gmail.com"; // Sets SMTP server for gmail
$Mail->SMTPDebug = 0; // 2 to enable SMTP debug information
$Mail->SMTPAuth = TRUE; // enable SMTP authentication
$Mail->SMTPSecure = "tls"; //Secure conection
$Mail->Port = 587; // set the SMTP port to gmail's port
$Mail->Username = 'fake.12345.account#gmail.com'; // gmail account username
$Mail->Password = 'a_password'; // gmail account password
$Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet = 'UTF-8';
$Mail->Encoding = '8bit';
$Mail->Subject = 'Mail test';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From = 'testing.num.101#gmail.com'; //Your email adress (Gmail overwrites it anyway)
$Mail->FromName = 'Testing Again';
$Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line
$Mail->addAddress($personEmail); // To: the PERSON WE WANT TO EMAIL
$Mail->isHTML( TRUE );
$Mail->Body = ' Good news '.$personName.'! The email sent correctly!';
$Mail->AltBody = 'This is a test mail';
$Mail->Send();
$Mail->SmtpClose();
if(!$Mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $Mail->ErrorInfo;
exit;
}
So the issue is: not having the email sent to $personEmail from fake.12345.account#gmail.com (that's trivial) but rather how to send the email from fake.12345.account#gmail.com to real.business#gmail.com such that real.business#gmail.com forwards the message to $personEmail
What you're describing is really relaying, which is usually configured in the mail server config (not the messages), but you don't have access to anything like that in gmail.
You can set allowed aliases in gmail, but I would guess that these are not allowed to overlap with existing gmail account names as that would be a major security hole. Why not enable "less secure apps" on the main account? It's not as if it is actually any less secure - if anything it's better, because the setup to use OAuth2 is so deeply complex and unpleasant...
That said, rather than trying to do all this forgery, you may be interested in this PR and associated docs. It's fairly likely the xoauth branch will get merged into master and released without any further changes as PHPMailer 5.2.11, and it would very helpful if you could give it a try.
PHPMailer is made for sending.
What you want to do is forward an email. This implies receiving the email and then sending it through.
What you need is some kind of IMAP client in php, that will allow you to read the emails on fake.12345.account#gmail.com (and maybe real.business#gmail.com). Then save their body and title and pass it to PHPMailer. You can then use PHPMailer to send the emails with real.business#gmail.com.
I'm trying to send a mail with PHPmailer and gmail. But when I send a mail its from my gmail account instead of no-reply. How do I set no-reply as from?
Code I have:
$mail = new PHPMailer();
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "myAccount#web.com";
$mail->Password = "password";
$mail->From = "no-reply#web.com";
$mail->AddAddress($to);
$mail->AddReplyTo("no-reply#web.com","no-reply");
$mail->Subject = $subject;
$mail->Body = $msg;
$mail->WordWrap = 150;
$mail->send();
The mail I get receives (headers):
Return-Path: <myAccount#web.com>
Which should be no-reply#web.com
Thanks in advance
There are two options I would recommend trying:
Log in to the Google Apps mail account for myaccount#web.com, go to Settings, then Accounts, then Send mail as, and ensure that no-reply#web.com has been validated. I haven't tested this, but this should allow to send mail from no-reply#web.com, rather than from no-reply#web.com on behalf of myaccount#web.com.
Actually create a user on Google Apps with the username no-reply#web.com, and send email through that account. If myaccount#web.com needs a copy, you could always BCC the address and setup a filter on no-reply#web.com to forward any failures to myaccount#web.com.
You can't do it. Just imagine sending mail prompting to reply with your bank account credentials from an address validation#yourbank.com.
To have no-reply address you must have an access to the mail server in #your.domain (not gmail) and create such account there, then send emails using this account.