I use gmail smtp for contact form in my site.(PHPMailer script https://github.com/PHPMailer/PHPMailer)
my code is:
<?php
include "classes/class.phpmailer.php"; // include the class name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // 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; // or 587
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "xxxxxxxxxx";
$mail->SetFrom("[email protected]");
$mail->addReplyTo("[email protected]");
$mail->Subject = "Your Gmail SMTP Mail";
$mail->Body = "Hi, your first SMTP mail via gmail server has been received.";
$mail->AddAddress("[email protected]");
if(!$mail->Send()){
echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
?>
It works but i have two problems:
I set $mail->SetFrom("[email protected]");
but in my gmail show from: [email protected]
I set $mail->addReplyTo("[email protected]");
but in my gmail when i click replay button email replayed to [email protected]
my code is
PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.
By default, gmail does not allow connections from third party software. If the option “access for less secure apps” is not enabled in the gmail account, users get the error “Unable to connect to SMTP host” in their websites.
Make sure that the DNS for SMTP host resolves correctly. Give port number as 25, the default SMTP port. For mail servers that use custom ports such as 587 for SMTP to avoid spamming, give that port. It is also possible that certain mail servers restrict the access to their port 25 using firewall rules.
PHPMailer is a code library, that is integrated` to send emails securely and effectively by means of PHP code from a web server. Sending emails specifically via PHP code uses a high-level environment to setup SMTP standard convention and related issues and vulnerabilities around Mail infusion for spamming.
Google does not allow you to send mail on behalf of another user [aka "spoof"] unless you've explicitly been allowed. If you have not been allowed it will rewrite the address to the address of the sending account.
To add an account log into gmail, and go to Settings > Accounts > Send Mail As... when you add an address here gmail will send a message to that address asking for confirmation to allow you to send mail on their behalf.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With