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

$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.

Related

PHPMailer sets the From same as the smtp username

I am using PHPMailer library to send SMTP email for booking enquiry. (Note: The same problem I was facing in PHP Pear Mail library as well).
I set the email from as below
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true;
$mail->Username = 'gmail.owner#gmail.com'; // SMTP username
$mail->Port = 465; // TCP port to connect to
$mail->isHTML(true);
$mail->Password = 'xxxx';
$mail->setFrom(mark.antony#example.com, Mark Antony);
$mail->replyTo(mark.antony#example.com, Mark Antony);
$mail->addAddress(gmail.owner#gmail.com, Gmail Owner);
$mail->Subject = $whatever subject;
$mail->Body = $whatever html;
The problem is after sending email in the received mailbox I see the From: is the same as To: (Or same as the gmail/smtp username).
I have fixed the problem on reply to by setting replyTo value.
Is there anyway I can fix this? Or is that how it suppose to be?
Google does not allow you to set arbitrary from addresses, because doing so is usually forgery. If you try to, gmail will ignore it and substitute your Username address, which is what you're seeing.
There is one exception to this: you can set up additional aliases in your gmail settings (which you need to verify), and once you've done that you can use those addresses as from addresses.
If you're using this for a contact form (as it sounds like you are), setting to and from to your own address, and the submitter as a reply-to is the correct way to go, as the PHPMailer contact form example demonstrates.

Setting target mail server PHPMailer

I have a list of mail servers that I would like to send an email to depending on the recipient address. For example, I have this array:
<?php
$_hosts = array("example.com" => "mx1.example.com", "domain.com" => "mx1.domain.com");
?>
So I would like when mailing user#example.com, to connect to mx1.example.com and drop the email there. I'm using PHPMailer to send an email to user#example.com using the following code:
$mail = new
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = '587';
$mail->SMTPSecure = 'tls';
...
$mail->addAddress("user#example.com");
This code works perfectly, except that it sends the message to the mail server at example.com. How can I instruct PHPMailer to send this email to mx1.example.com instead?
Do whatever you need to look up the address in your array, then set Host to the corresponding server you want to send through. If you leave it set to localhost it will always send through there.

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)');

Can I use gmail as smtp server for my website

Hello I am trying to get a website up and running. It is currently hosted on AWS, so I do not have my own smtp server running at this moment. So after reading a few articles, I have understood that we could used gmail as a smtp server.
I wanted to double check if what I read was right, I am going to use smart job board software, can I plug in the values provided by gmail and use that as an smtp server??
Yes, Google allows connections through their SMTP and allows you to send emails from your GMail account.
There are a lot of PHP mail scripts that you can use. Some of the most popular SMTP senders are: PHPMailer (with an useful tutorial) and SWIFTMailer (and their tutorial).
The data you need to connect and send emails from their servers are your GMail account, your password, their SMTP server (in this case smtp.gmail.com) and port (in this case 465) also you have to make sure that emails are being sent over SSL.
A quick example of sending an email like that with PHPMailer:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // SMTP authentication
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->Port = 465; // SMTP Port
$mail->Username = "john.doe#gmail.com"; // SMTP account username
$mail->Password = "your.password"; // SMTP account password
$mail->SetFrom('john.doe#gmail.com', 'John Doe'); // FROM
$mail->AddReplyTo('john.doe#gmail.com', 'John Doe'); // Reply TO
$mail->AddAddress('jane.doe#gmail.com', 'Jane Doe'); // recipient email
$mail->Subject = "First SMTP Message"; // email subject
$mail->Body = "Hi! \n\n This is my first e-mail sent through Google SMTP using PHPMailer.";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>
I successfully use the GMail SMTP server.
We do have a corporate GMail account, though I don't think that matters. A personal GMail account should suffice.
I do not have a PHP sample however the following configuration for ASP.Net should provide adequate guidance:
<mailSettings>
<smtp from="me#gmail.com">
<network enableSsl="true" host="smtp.gmail.com" port="587" userName="me#gmail.com" password="mypassword" />
</smtp>
</mailSettings>
If someone has a suitable PHP sample, feel free to edit my answer or post your own.
Authentication is required I believe, but I don't see why not. I won't do the research for you, but there are a couple things to look into:
Their SMTP server requires TLS encryption and is hosted on a non-standard port (995). You will need to ensure that AWS supports both of these options for SMTP outbound.
There is probably a cap on emails you can send before being marked as spam. You should research this and ensure it is not beyond your requirements.
You can user PHPMailer class for this job. And you can easily configure the smtp.
An example of configuration
if (class_exists(#PHPMailer)) {
$smtp_mail = new PHPMailer();
$smtp_mail->isSMTP();
$smtp_mail->SMTPAuth = true; // enable SMTP authentication
$smtp_mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$smtp_mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$smtp_mail->Port = 465; // set the SMTP port
$smtp_mail->Username = "info#example.com"; // GMAIL username
$smtp_mail->Password = "password"; // GMAIL password
$smtp_mail->From = "info#example.com";
$smtp_mail->FromName = "Name";
$smtp_mail->AltBody = "This is the body when user views in plain text format"; //Text Body
$smtp_mail->WordWrap = 50; // set word wrap
$smtp_mail->AddReplyTo("info#example.com","Name");
$smtp_mail->isHTML(true); // send as HTML
}
Although you can technically use Gmail as SMTP server, it is not recommended for larger websites. By time you may receive issues like "421 4.7.0 Temporary System Problem" or similar, is it was not designed to be used by an application, rather a single person.
Related issue for the error message above:
Gmail SMTP error - Temporary block?

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