I have setup gsuite email and want to use it for emails that my website sends when someone registers etc. I have setup phpmailer to do that.
$email = new PHPMailer();
$email->Host = "stmp.gmail.com";
$email->SMTPDebug = 2;
$email->SMTPAuth = true;
$email->SMTPSecure = "ssl";
$email->Port = 465;
$email->Username = "myemail#mydomain.com";
$email->Password = "password";
$email->AddReplyTo('myemail#mydomain.com', "My Email");
$email->SetFrom('myemail#mydomain.com', "My Email");
$email->AddAddress("email#gmail.com");
$email->AddAddress("email#live.com");
$email->Subject = "test email";
$email->MsgHTML("<a>This is test</a>");
$email->Send();
I have tried to change subject/content of the email, also tried tls/587 but it sends email to gmail but not to live which I think I don't want to miss out.
Turns out my ip was listed in spamhaus, which they cleared after I contacted them. Now I receive emails on live.com as well.
Related
I'm using the PHPMailer to my website contact page , but I faced a problem , when the message is received both sender and receiver gmail are the same?
use PHPMailer\PHPMailer\PHPMailer;
if (isset($_POST['name']) && isset($_POST['email'])) {
$name = filter_var( $_POST['name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['mail'],FILTER_SANITIZE_STRING);
$subject = filter_var($_POST['subject'],FILTER_SANITIZE_STRING);
$body = filter_var($_POST['body'],FILTER_SANITIZE_STRING);
require_once "PHPMailer/PHPMailer.php";
require_once "PHPMailer/SMTP.php";
require_once "PHPMailer/Exception.php";
$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';
//SMTP Settings
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "#gmail.com"; //enter you email address
$mail->Password = ''; //enter you email password
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
//Email Settings
$mail->isHTML(true);
$mail->setFrom($email,$name);
$mail->addAddress("ennokhba22#gmail.com"); //enter you email address
$mail->Subject = ($subject);
$mail->From= $email;
$mail->Body = $body;
When sending via Gmail's SMTP servers, they ignore any From headers to prevent abuse. Your From will always be that of the Gmail account you're sending via.
You'll need a different email service provider if you want to send custom From headers, but note that this is likely to wind your emails up in spam unless you've got the rights (via SPF etc.) to send email on behalf of that custom address. You might consider a Reply-To header instead.
I am trying to send SMS using phpmailer with my gmail account.
This is my code:
require_once('../class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Username = "myusername#gmail.com";
$mail->Password = "mypassword";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SetFrom('myusername#gmail.com', 'DS');
$mail->Subject = 'hello';
$mail->Body = 'this is a testing mail..';
$mail->AddAddress('xxxxxxxxxx#ideacellular.net','testname');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
xxxxxxxxxx#ideacellular.net denotes the mobilenumber#carrierdomain.
When I execute this script. Output is that : Message sent!
But the sms is not received.
Please let me know if there is any mistake in my code (or) is it a invalid way to send SMS using phpmailer.
Using this code (change AddAddress field to email instead of mobile number) I can send mail.
But SMS cant be sent.
IS this possible to send SMS using phpmailer?
Please help me to resolve this problem..
Any help is greatly appreciated.
Seems that issue with 'ideacellular.net'.
Most phone companies have an email gateway which permits you to send an SMS message to their customers via email. You'll need to determine for each service provider what that email address looks like and set up some code to turn their phone number and service provider combination into the appropriate email address.
Check this link:
http://www.tech-recipes.com/rx/939/sms_email_cingular_nextel_sprint_tmobile_verizon_virgin/
Following code works with verizon
require 'class.phpmailer.php';
$mail = new PHPMailer();
// Configure SMTP
$mail->IsSMTP();
$mail->SMTPDebug = 2; // verbose information
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Encoding = '7bit';
// Auth
$mail->Username = "email.address#gmail.com";
$mail->Password = "password";
// Check
$mail->Subject = "Testing";
$mail->Body = "Testing";
$mail->AddAddress( "###########vtext.com" );
var_dump( $mail->send() );
UPDATE
To send a text message from an email, you need to know the address for the SMS gateway. Below is a list of the SMS gateways for some of the major US cellular providers. If a carrier is not in the list, search the website for that carrier and you will likely find their SMS gateway address.
AllTel: number#message.alltel.com
AT&T: number#txt.att.net
Boost Mobile: number#myboostmobile.com
Cricket: number#sms.mycricket.com
Nextel: number#messaging.nextel.com
Qwest: number#qwestmp.com
Sprint: number#messaging.sprintpcs.com
T-Mobile: number#tmomail.net
Tracfone: number#mmst5.tracfone.com
U.S. Cellular: number#email.uscc.net
Verizon: number#vtext.com
Virgin Mobile: number#vmobl.com
Also, you may check this link for the list of other providers:
http://www.emailtextmessages.com/
I am facing this problem where the mail is getting sent as a different email rather than the one specified.
$from_name = 'send';
$from = 'send#test.com';
$to = 'receive#test.com';
$to_name = 'receive';
$also_to = 'cc#test.com';
$also_to_name = 'cc';
$message = 'Dear receive Thank you for the booking';
$message .= '<br><br>'.$homepage;
$mail = new PHPMailer();
$mail->SMTPDebug = 0;
$mail->IsSMTP();
$mail->Port = 465;
$mail->Host = "ssl://smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = 'send1#test.com';
$mail->Password = ******;
$mail->SetFrom($from,$from_name );
$mail->AddReplyTo($from,$from_name );
$mail->Subject = 'Booking Details';
$mail->MsgHTML($message);
$mail->AddAddress($to,$to_name);
$mail->AddCC($also_to,$also_to_name);
When I sent it using this code the mail goes with name as 'send' but not the 'send#test.com' email address it gets sent from "send -> send1#test.com" rather than send -> send#test.com.
Above I have mentioned the smtp details that i have used. Also when i change:
$mail->Username = 'send#test.com';
$mail->Password = ******;
The mail does not go through to any email address. I hope this is clear enough for you guys and I would appreciate any help. Thank you
$mail->Username = send1#test.com;
this need to be in quotes like :
$mail->Username = "send1#test.com";
Check whether this resolves you issue ?
If not try setting debug to true $mail->SMTPDebug = 1;
and see what's being actually sent to gmail server
By default gmail will use the account's email address
Ref : How to change from-address when using gmail smtp server
Look at this: http://phpmailer.worxware.com/index.php?pg=properties
$From public root#localhost Sets the From email address for the message
and
$FromName public Root User Sets the From name of the message
So you want specifically add the following:
$mail->From = $from;
$mail->FromName= $from_name;
You have to call setFrom method to set the sender's mail address and name:
$mail->SetFrom('send#test.com', 'Your Name');
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'm using the following code to send a mail after a form submission with the PHP mailer class https://github.com/Synchro/PHPMailer. The mail sends and is received successfully. The only thing that isn't wokring is the following:
$mail->From = $email;
$email is the email that a user will enter on the form (it is set with a $_POST variable). I would like the email to appear that it's from the user who filled out the form, so I can hit reply and have it go to their email address.
However, the "from" email address is being set as $mail->Username, i.e. the username from the gmail account that the PHPMailer script is sending from.
What am I doing wrong here, and how do I get the From email header to work?
Also, I am using Gmail to receive the mail-- maybe there's a gmail security setting that won't allow the "From" email to be "faked"???
Thanks!
$email = $_POST['email'];
$name = $_POST['moveName'];
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'ssl://smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = 'example#gmail.com';
$mail->Password = 'password';
$mail->From = $email;
$mail->FromName = $name;
$mail->AddAddress('me#gmail.com');
$mail->AddReplyTo($email, $name);
$mail->IsHTML(true);
$mail->Subject = 'Quote Request';
$mail->Body = 'hey';
$mail->Send();
With gmail you have to configure an email address as allowed "$mail->from" first. This FAQ entry explains how to do it: https://support.google.com/mail/answer/22370?hl=en