My webhost does not allow mail accounts to be created. However they have provided me with their SMTP gateway and said no credentials are needed when the mails are being sent from their datacenter.
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Host = GATEWAY_PROVIDED_BY_HOST
$mail->SMTPAuth = false;
$mail->SMTPSecure = false;
Invalid address: (From): root#localhost
It seems I need to add a from address. But in the case that they do not allow a mail account to be created, what do I put in the from address?
Try to use a valid sender "from" email address.
Update:
You have to use a sender address which is the mail server responsible for (or a white listed one).
normal "#domain.tld" is enought. the name in front of the at is often not tested.
Also possible: you can only send "to" the domain which is the mail server responsible for or you have to authenticate. best is you contact your server provider.
You need to set a From address:
$mail->setFrom('user#example.com', 'My Name');
This will set the from address that appears in message headers, but it will also used as the MAIL FROM command at the SMTP level (where your error is coming from) as it's automatically copied to the Sender PHPMailer property which applies there. That will avoid the fallback to the root#localhost address you're getting.
The other things you're doing to disable authentication are correct.
Create a Google Account and use it:
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Username = "your#gmail.com";
$mail->Password = "*****";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
$mail->setFrom('your#gmail.com', 'Your Name');
$mail->addReplyTo('your#gmail.com', 'Your Name');
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.
I am using PHP Mailer library to send mail. Here I set from email address. But that email does not show in the mail.
$mail->SMTPDebug = env("GMAIL_SMTP_DEBUG");
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "mygroup#gmail.com"
$mail->Password = "******";
$mail->SMTPSecure = env("GMAIL_SMTP_SECURE");
$mail->Port = env("GMAIL_SMTP_PORT");
$mail->ContentType = 'text/html; charset=utf-8\r\n';
$mail->WordWrap = 900;
//Recipients
$mail->Sender = "myemail#gmail.com";
$mail->SetFrom("myemail#gmail.com", "My Name",false);
.......
Here I want to receive from address is "myemail#gmail.com". But instead of I am getting "mygroup#gmail.com"
What you're asking for is effectively forgery, and gmail (along with other services) doesn't allow it - it will substitute your account address instead, as you're seeing.
The one thing you can do is set up fixed aliases for your account in your gmail settings, and you can then use those as from addresses, and gmail won't substitute them. Even with this, it still won't let you use arbitrary from addresses on the fly - you have to define them beforehand.
I used the following code snippet using phpmailer class inorder to send an email using gmail server when a form is submitted in my web application! Though it works for my personel gmail address, it does not send emails when I replace my gmail address and password with my clients gmail address and password!
How can i correct this probem?
require "phpmailer/class.phpmailer.php"; //include phpmailer class
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "ssl"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 465; //Gmail SMTP port
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "sunethperera#gmail.com"; // Your full Gmail address
$mail->Password = "******"; // Your Gmail password
// Compose
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "Pharmacy order confirmaton"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress($_POST["Email"], "Recipient Name"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
When I send the message from my client's email, I get the error message:
SMTP Error: Could not authenticate.
How can I correct this issue?
Trying using this:
$mail->SMTPSecure = "tls";
Remove the Encoding parameter
And also check you have the correct from address and the password as well.
Update your PHPMailer right now. You are running an old vulnerable version. Read the troubleshooting guide and do what it says. Do not use the submitter's address as the from address - its forgery and will make you fail SPF checks. Gmail does not let you send from arbitrary from addresses. Your auth problem is covered in the guide, but you will need to either enable less secure apps in Gmail, or implement oauth, as described in the docs and examples.
This has all been covered many times on SO - search before you post.
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.
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";