I am using the following code to send emails using phpmailer 6:
$mail->isSMTP();
$mail->Host = 'myhost';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = 'email#mydomain.com';
$mail->Password = 'password';
$mail->Port = '587';
$mail->ContentType = 'text/plain';
$mail->IsHTML(false);
$mail->setFrom('email#mydomain.com');
$mail->addReplyTo($_POST['email'], $_POST['name']);
$mail->addAddress($to);
$mail->Subject = $_POST['subject'];
$mail->Body = "...";
$mail->send();
The email sends successfully to our company, however it always says it is from email#mydomain.com, which makes it hard for staff to find specific emails in their inbox. In the form, the user provides their name and email so ideally I'd like it to appear in Outlook as being sent from John Doe (jdoe#gmail.com) rather than email#mydomain.com.
In old versions of webforms I use to do this by setting the from address however now that doesn't seem to be possible because it's considered spoofing.
Is there a way to accomplish this?
Simply add in the name as the second parameter in your setFrom. See the example below:
$mail->setFrom('darth#empire.com', 'Darth Vader');
It'll then appear as you want it!
Related
I am using PhpMailer class to send emails that contains html,I noticed that if the body on email contain img tags the email not receiving and no errors showing.
Any suggestions?
my code so far:
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'ssl';
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "myusername";
$mail->Password = "mypassword";
$mail->setFrom($from);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->Body =$body;
$mail->IsHTML(true);
if ($mail->send()) {
return 1;
} else {
return 0;
}
if you're trying to send it from localhost and read in gmail, it won't work because gmail often creates proxy image links. you need to send image links that direct to internet-accessible location. That's probably it.
If you're sending email with links to internet-accessible locations, please attach them to the question and I'll update the answer, too.
EIDT: after chat with the asker, it was determined the email HTML was missing normal HTML markup: <html><body>ACTUALCONTENT</body></html>, after adding those,image shown up correctly.
You can use the AddEmbeddedImage method to attach image to your body. So your code should look like this.
$mail->AddEmbeddedImage($_REQUEST['image_name'], 'ImageName');
And then in your $body you can use this image
$body.= "<img src='cid:ImageName' />";
I'm using Yii phpmailer extension to send mail using gmail but it showing SMTP Error: Could not authenticate. instead of sending mail. My code what I used
Yii::import('application.extensions.phpmailer.JPhpMailer');
$mail = new JPhpMailer;
$mail->IsSMTP();
//$mail->Host = 'smpt.163.com';
$mail->Host = 'smtp.googlemail.com:465';
//$mail->Host = 'smtp.gmail.com:587';
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Username = $email;
$mail->Password = $pass;
$mail->SetFrom($email, SiteConfig::SITE_TITLE);
$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
$mail->MsgHTML('<h1>JUST A TEST!</h1>');
$mail->AddAddress($email, 'My Name');
$mail->Send();
I followed this link.
How can I solve this problem and send mail using gmail? I’d appreciate any light you can shed on this!!
Try adding the following line:
$mail->Port = 465;
I am unsure if adding :port works for the Host field as you've done - I can confirm that setting the Port field manually does work, as I have a large system whose code looks very similar to yours which is working as expected.
We also use $mail->Host = 'smtp.gmail.com' but I am almost certain that the smtp.googlemail.com domain should also work.
You can debug and get error report
for 1 error and message
for 2 message only
$mail->SMTPDebug = 2; // debugging: 1 = errors and messages, 2 = messages only
Be sure to set the following attributes:
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPSecure = "tls";
$mail->SMTPAuth = true;
$mail->Username = "your username";
$mail->Password = "your password";
It should work with those attributes set.
Hope it helps.
I have a contact form which a user types his/her details including his/her email, the code below works well
$mail = new PHPMailer();
$body = $message;
$mail->IsHTML(true);
$mail->SMTPAuth = true;
$mail->Host = "smtp.bizmail.yahoo.com";
$mail->Port = 587;
$mail->Username = "name#domainname.net";
$mail->ContentType ='text/html';
$mail->Password = "password";
$mail->SMTPSecure = 'tls';
$mail->SetFrom('name#domainname.net', 'my name',false);
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->IsSMTP();
$address = $to;
$mail->AddAddress($address, $name);
if(!$mail->Send()) {
return 0;
} else {
return 1;
}
this code sends a mail and a header "From: name#domainname.net", but i want to show the email the user inputs from the contact form. e.g a user inputs myenquiry#anotherdomain.com, i want the from mail to be "From: myenquiry#anotherdomain.com" in which anotherdomain is not in my domain (i.e yahoo small business)
Don't do that. That is forging the from address and it will usually cause your messages to fail to be delivered because they will fail SPF checks. This is especially the case with Yahoo who is by far the pickiest ISP to deliver to. Put your own address in From (as you are doing now), and add the submitter's address in reply-to (see addReplyTo() in PHPMailer).
Also you've based your code on an old example, so make sure you are using an up to date example and the latest PHPMailer.
I have managed to send a mail to myself using this code.
$mail = new PHPMailer;
//$mail->SMTPDebug = 1;
//Email server info
$mail->isSMTP();
$mail->Host = 'smtp-mail.outlook.com';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
//User authentication info
$mail->SMTPAuth = true;
$mail->Username = '******#hotmail.com';
$mail->Password = '********';
//Email info
$mail->From = 'noreply#ledii.net';
$mail->FromName = 'LediiNet';
$mail->addAddress($mail->Username);
$mail->Subject = 'LediiNet Feedback';
$mail->Body = 'Here are some thoughts...';
Is it possible to make it so that the mail will show up with my website name as sender insteath of my name and email?
I would preferrably want it to seem like the mail is sent from noreply#ledii.net and with the sender name of LediiNet.
I feel like I probably have to actually create that email somehow and connect to my host servers email server info?
I figured out how to do it, but I had to change to using the mail() function and modify my local files for it to work locally.
I know this question has been asked before but my issue is a bit different. I use the php mailer to send a bulk of mails in a loop to customers from the database. In the body of the mail when there's no html stuff like body = "hello" the emails get delivered to the normal inbox. However, when I use html tags in $mail->Body then the email goes to spam. The code I use:
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'someone'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'someemail.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls';
$mail->From = 'someemail.com';
$mail->FromName = 'Mailer';
#$mail->addAddress($email); // Name is optional
$mail->addAddress('someemail.com');
$mail->AddEmbeddedImage('rr.jpg', 'logoimg', 'rr.jpg');
$mail->AddEmbeddedImage('bottom.gif', 'bottomimg', 'bottom.gif');
$mail->WordWrap = 100; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$username = "123";
$mail->Subject = 'Welcome';
$mail->Body = "Hello, welcome"
$mail->AltBody = 'Welcome ';
$mail->send()
The issue is only with gmail. All other major mail providers such as yahoo, hotmail and live are fine. The emails go to inbox. It may be because I use quite a lot of html, colors etc in the email. But I don't know why gmail moves the mail to spam simply because it looks like many other spam mails. Is there any solution?