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.
Related
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.
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'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.
I search to send mail with php script.
$mail = new PHPmailer();
$mail->IsSMTP();
$mail->Host='mail.mydomaine.com';
$mail->From='xxx#mydomaine.com';
$mail->AddAddress('xxx#yahoo.fr');
$mail->AddReplyTo('xxx#mydomaine.com');
$mail->Subject='test';
$mail->Body='example for mail';
if i make From address yyy#mydomaine.com it is work but if i change it to example yyy#gmail.com or yahoo.fr it do not work. this the error message
SMTP Error: The following recipients failed: xxx#yahoo.fr
SMTP server error: 5.7.1 : Relay access denied
If you want to use yyy#gmail.com or yyy#yahoo.com as from address, You need to configure respective mail server with authentication(mail account). For example, if you want to configure gmail configure like this..
$mailObj->Host = 'smtp.gmail.com';
$mailObj->Port = '465';
$mailObj->Username = 'yyyy#gmail.com';
$mailObj->Password = 'passwordofaboveaccount';
Now
$mailObj->From='xxx#gmail.com';
will work
you can add the mail for site....
$mail->Host = 'smtp.gmail.com';
$mail->Port = '465';
$mail->Username = 'yyy#gmail.com';//your mail is valuable
$mail->Password = 'password';//your mail pass
if you need to change the mail to yahoo then simply change the host name with the yahoo smtp.......
How could you ever send email with someone elses email address? You can ofcourse only send from your own domain, if this PHP code is on your server.
do you have the following, yes?
$mailObj->SMTPAuth = TRUE;
$mailObj->SMTPSecure = "ssl";
Is it possible to use Google's mail server for testing purpose,and replace the address of mail server when my own server is ready?
You can just send your mails via smtp.gmail.com (port 465 or 587) as with any email client. Note anyway that you will need a Google email account for this. More details are here: Configuring email clients for using GMail
I suggest you to use phpmailer, this is an example working code with it:
<?php
include_once("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
// enable SMTP authentication
$mail->SMTPAuth = true;
// sets the prefix to the server
$mail->SMTPSecure = "ssl";
// sets GMAIL as the SMTP server
$mail->Host = 'smtp.gmail.com';
// set the SMTP port
$mail->Port = '465';
// GMAIL username
$mail->Username = 'your.gmail.user#gmail.com';
// GMAIL password
$mail->Password = 'your-gmail-password';
$mail->From = 'email address who send the email';
$mail->FromName = 'yourname';
$mail->AddReplyTo('email to reply', 'name to reply');
$mail->Subject = 'Test Gmail!';
if($is_your_mail_an_html){
$mail->MsgHTML($html_message);
$mail->IsHTML(true);
}else{
$mail->Body = $text_message;
$mail->IsHTML(false);
}
$mail->AddAddress('to address email', 'to name');
if(!$mail->Send()){
echo = $mail->ErrorInfo;
}else{
$mail->ClearAddresses();
$mail->ClearAttachments();
}
?>
But even without phpmailer, you can use gmail to send emails; Just set the port to 465 and enable the ssl auth.
P.s.: dont try to send nesletter throught gmail; they will block your account for 1 day if you send more than $x email per day ($x is 500 on the google documentation, but my experience say that is around 85!)
Yes google does offer that via smtp.
smtp.google.com
port: 587
You also will need your google username and password to send emails.
You need a php smtp class. PHPMailer has one.
If you run a Windows server you can just do this (if you have access to the php.ini). Otherwise follow Sarfraz suggestion.
<?php
ini_set('sendmail_from','test#test.com');
ini_set('SMTP','smtp.test.net');
mail(...);
?>