How to set FROM in php mailer using Gmail SMTP - php

I was trying to set from in php mailer (gmail smtp). But in inbox it shows from mygmailaccount#gmail.com. here is my code :
$this->_mail->Username = "mygmailaccount#gmail.com";
//Password to use for SMTP authentication
$this->_mail->Password = 'mypassword';
$this->_mail->From="support#mydomain.com";
$this->_mail->FromName="Support Team";
//Set who the message is to be sent from
$this->_mail->setFrom('support#mydomain.com', 'Support Team',false);
But when I receive email in inbox its show from : mygmailaccount#gmail.com
and I want to show from : support#mydomain.com
Can anyone help me to find out what I am missing.

This is a gmail restriction, though it's not all bad news! In your gmail preferences you can configure aliases for your account, and you can send out using them as your from address. So you can set the from address, but only to a choice from that preset list, not any arbitrary address. This question has been asked on here before.

Related

Send mail from Gsuite mail alias with PHPMailer

I'm trying to use PHPMailer on my website to send mail as part of a contact form. I would like to use contact#example.com instead of standard_email#example.com to send mail, for filtering and security. My mail is handled by GSuite (formerly called Google Apps) and is setup like below:
User - standard_email#example.com
Alias - contact#example.com --> standard_email#example.com
I have sending working perfectly when using standard_email#example.com in the PHPMailer configuration, but when I try to send using the alias it does not work. Is this not possible with GSuite aliases?
Contact Controller
define("SMTP_HOST", "smtp.gmail.com");
define("MAIL_ADDRESS", "alias#example.com");
define("SMTP_USERNAME", "alias#example.com");
...
//Configure SMTP authentication
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = SMTP_HOST;
$mail->SMTPAuth = true;
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
$mail->SMTPSecure = "tls";
$mail->Port = SMTP_PORT;
//Set email headers
$mail->setFrom(MAIL_ADDRESS, "Contact Us Submission");
$mail->addAddress(MAIL_ADDRESS, "Contact Us Submission");
$mail->addReplyTo($form_email, $form_name);
$mail->isHTML(true);
//Set email content
$mail->Subject = htmlspecialchars($form_subject);
$mail->Body = htmlspecialchars($form_comments);
$mail->AltBody = htmlspecialchars($form_comments);
//Attempt to send the message and display the results to the user
if ($mail->send() == false) {
return new MailResponse(1, "Message could not be sent", $contactSubmission);
} else {
return new MailResponse(0, "Message sent successfully", $contactSubmission);
}
I've also tried using standard_email#example.com as the SMTP_USERNAME and alias#example.com as the MAIL_ADDRESS, but that didn't work either.
Results
There are no reported errors, and the page displays the "success" mail message; however, no mail is actually sent/received when I visit my user. Since GSuite apparently routes all of the alias mail to my standard address, I should be seeing it.
Let me know if I'm missing something, and thanks!
The solution from #Synchro works and for convenience here is a short step by step solution:
On your computer, open Gmail.
In the top right, click Settings Settings and then See all settings.
Click the Accounts and import or Accounts tab.
In the "Send mail as" section, click Add another email address.
Enter your name and the address you want to send from.
Click Next Step and then Send verification.
Click Add Account
Learn more: https://support.google.com/mail/answer/22370?hl=en
Everything should be working now :)

use of PHPMailer about some of its methods e.g. `addReplyTo()` & `setFrom()`

$mail->Host = "smtp-mail.outlook.com";
$mail->Port = 25;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = "h*****#outlook.com";
$mail->Password = "********";
$mail->setFrom("h****#gmail.com", "Z***** Hao");
$mail->addReplyTo("a********#yahoo.com", "Z****** Hao");
$mail->addAddress("h******#qq.com", "Z**** Hao");
Above is my code try to use PHPMailer sending email through the outlook smtp server,and my qq mailbox received an email from my outlook account,but I thought it would be sent from my gmail account since I used the setFrom() method,and also how can the $mail->addReplyTo statement play a part in it?
And as a beginner I write it down by referencing an example on github page of PHPMailer project,it's the Link.
As currently configured, you're doing this:
Host, Port, SMTPSecure, SMTPAuth: Configure the mail server you want to use to send out the e-mail. In this case it's the Outlook SMTP server.
Username and Password: Credentials you're using to login to the Outlook SMTP server.
setFrom sets the From header in the email message. You're currently setting this to your Gmail address, so most of the time, the receiving party sees this address in his/her email client in the from field. But: this header isn't always respected by the sending SMTP server. It could be replaced by the email address belonging to your credentials to prevent spam.
addReplyTo allows you to set a different reply-to address. If not set, the client will suggest to sent an email to the address as specified in the From field. This allows you to overwrite it.

How to use my customers' email sending their email as the "Sender"

I used to use "Php mailer" to authenticate using a user's email and password to send from their address in my app, but it is such an inconvenience.
So I want to do something like "Mailchimp" does. Mailchimp allows a user to set their email and then Mailchimp just uses user's email as the "Sender".
Please anyone help me with this email issue.
You can't. MailChimp requires you to verify yourself as the owner of the e-mail address and domain through DNS settings. See more details
What you need to do is first verify the user's email address is correct. Here is a good walk-through that shows how to do that:
http://code.tutsplus.com/tutorials/how-to-implement-email-verification-for-new-members--net-3824
You'll also want a disclaimer as proof that they have given you permission to send emails on their behalf.
Disclaimer: by enrolling for this service you are granting this
app permission to send emails on your behalf.
Next you'll want to create a functional email account that belongs to your app only. For example:
clientmailer#myapp.com
Then, last but not least- continue to use PHPMailer, but use it differently. Authenticate and send emails from your app's functional account, but set the AddReplyTo address as your customer's address and name. For example:
select email, firstname from client;
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tsl';
$mail->SMTPDebug = 1;
$mail->Host = yourhost#myapp.com;
$mail->Port = EMAIL_PORT;
$mail->Username = clientmailer#myapp.com;
$mail->Password = yourpass;
$mail->SetFrom('clientmailer#myapp.com', 'Functional Mailer');
$mail->AddReplyTo('(email from select)', '(firstname from select)');

PHP bulk mail using "phpmailer" lands in SPAM

I am using the following PHP CODE to send BULK MAIL .But Mails seems to Land in SPAM.I am using "phpmailer" class to send the mail.
require 'mailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "info#gmail.com";
$mail->Password = "Bexwa44Puciz"; // GMAIL password
$mail->AddReplyTo('info#gmail.com', 'Info');
$Appname = 'info.com';
$_subject="Newsletter From: ".$Appname;
$ema=",";
$to_bcc=explode(",",$ema);
$mail->AddCustomHeader($headers);
foreach($to_bcc as $tb){
$mail->AddBCC($tb, $dname);
}
$_body ="News content";//$hid;
$mail->FromName = "info.com";
$mail->From="inf#gmail.com";
$mail->Subject = $_subject;
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($_body);
if($mail->Send()){
echo "Done";
}else {
echo "Failed";
}
I experienced same. My website sends requests for data confirmation to users a few times each day while I do my daily data maintenance. I sent a test message to my Gmail address and found that if you read your mail through Gmail webmail interface it will sometimes tell you Why the message was spammed. Very useful. It gave the reason "A lot of messages from hp19.hostpapa.com were spam". I am on a budget shared server and I assume a hundred other spammers have bought accounts on the same machine as mine and are using it for evil. My site is non-profit so buying a dedicated box to avoid spam is not an option. So...
My solution was to change my CMS to not use PHP mail() at all. Now my CMS simply displays the message and a mailto: link with Subject parameter set. Now my process is to hit CTRL+C, Click the link, CTRL+V, and hit send. Messages are sent from my computer's IP Address (not on any blacklist) using my mail client, Thunderbird.
This takes me just a couple of seconds longer than it did when my CMS used PHP mail() to send the message for me. However I have found I am receiving a lot more replies so I am happy that the vast majority of messages are not getting spam-binned.
I appreciate this manual solution is not appropriate for automated bulk messaging but for small non-profit sites on shared server who trigger each message with a click, I thought it was worth sharing.
There are a number of reasons you could be going into someones spam box. Your email server could be blacklisted due to either you, or another user on your server. You can check it at http://mxtoolbox.com/blacklists.aspx
Also check your SPF records in your DNS

Email System in PHP using PHPMailer

Hi i am currently implementing an email system for a customer in php. I'm having a bit of trouble in figuring out something. Here's a sample code:
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 0; // 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 = "***missing part***";
$mail->Password = "***missing part***";
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
My customer already created a business email account on gmail for this website. My question is should i put this business email and password in these missing parts? Anyone could help me please? Thanks.
whose username and password should i put there?
If you want to use GMail, you need to put in the username and password that belong to the GMail account you want to send the message from.
.... which is why sending E-Mail through GMail is a bit of an imperfect solution IMO - you put your personal Google login data, with which you can access everything you do on Google, into a script on a server. It's not great practice security-wise.
It might be more feasible to create a SMTP account on the client's web site, and use that. That has the additional advantage that you can use a email#clients-domain-name.com sender address.
you must post the username and password so we can help you.. LOL, just kidding. You should put there the username and password of the account that would be sending the email. In this case, probably your webpage's gmail account.
Often web hosts don't use authentication for their web servers to send email using their smtp servers, i would suggest contacting the people who host the website and ask them about using their smtp servers.
Using gmail (if you can from a script) might end up with the rather annoying reply thing that you get from gmail where the reply address is a gmail account.
e.g. from mrKoz#gmail.com on behalf of mr#koz.com which doesn't look awesome :)

Categories