I am trying to send an email using phpmailer. I have set the encryption to "none" to send using plaintext, however, it starts TLS. I am able to telnet manually to the server and successfully send the email in plaintext, meaning that the server supports plaintext and is not enforcing TLS. Here are the settings and traffic capture:
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = MAILSRV;
$mail->Port = "25";
$mail->SMTPSecure = "none";
$mail->SMTPAuth = "1";
$mail->Username = MAILUSER;
$mail->Password = MAILPASS;
$mail->IsHTML(true);
$mail->setFrom(MAILFROM, "Test");
$mail->CharSet = "utf-8";
$mail->Encoding = "base64";
$mail->addAddress(MAILTO);
$mail->Subject = SUBJECT;
$mail->msgHTML(BODY);
Server sends RST after client hello. How can I configure phpmailer to send the email with no encryption?
Don't make up random stuff and expect it to work; pay attention to the correct types and values of PHPMailer properties, ideally by reading the API documentation.
$mail->Port = "25";
Port is an integer, not a string.
$mail->SMTPSecure = "none";
If you're trying to turn it off, set it to an empty string (as the source code says), not some random value, though it is off by default so you don't have to do this anyway.
$mail->SMTPAuth = "1";
This is a boolean value, and it already defaults to false.
$mail->Encoding = "base64";
This is generally a bad idea, and makes your messages more likely to be classified as spam.
But to get to the point of your question, PHPMailer uses opportunistic encryption, meaning that if your server advertises it, PHPMailer will automatically attempt to use it. This can fail in some circumstances, usually when the target mail server is misconfigured in some way, but the thing you are looking for is:
$mail->SMTPAutoTLS = false;
and the documentation on it is here.
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 am hosted at A2 hosting, but I am using GSuite to handle all my mail.
When I send test message to mail-tester.com from Gmail I get an awesome rating.
However when I sent a message using my PHP script:
$mail = new PHPMailer(true);
ob_start();
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $pickuploc . '#xxxx.com'; // SMTP username
$mail->Password = 'xxx';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom($pickuploc . '#xxx.com', 'xxx xxxx');
$mail->addAddress($email, $fname . " " . $lname); // Add a recipient
$mail->addBCC($pickuploc . '#xxx.com');
// Content
$mail->isHTML(true); // Set email format to HTML
include 'email-confirmed.html';
$mail->Subject = 'Your Reservation Has Been Confirmed!';
$mail->Body = ob_get_clean();
$mail->AltBody = 'Your reservation has been confirmed.';
$mail->send();
I get an error from mail-tester.com that reads my DKIM is not valid.
I think this is because I am sending form a foreign server (not Google) and my MX records point to Google, but I really need these emails to get though, how should I work this problem?
Is there a way to configure this in PHP Mailer? Thanks.
The reason it's complaining is because you're not signing with DKIM at all!
You can do DKIM signing with PHPMailer, but there's a certain amount of setup required. PHPMailer provides some code to help you do this. Make sure you're using PHPMailer 6.1.1 or later; older versions have bugs affecting DKIM signing.
First of all you need to create your DKIM keys and put them in your DNS.
Now you need to alter your script to sign messages using your private key, as shown in this example; the parts you need to add are:
//This should be the same as the domain of your From address
$mail->DKIM_domain = 'example.com';
//See the DKIM_gen_keys.phps script for making a key pair -
//here we assume you've already done that.
//Path to your private key:
$mail->DKIM_private = 'dkim_private.pem';
//Set this to your own selector
$mail->DKIM_selector = 'phpmailer';
//Put your private key's passphrase in here if it has one
$mail->DKIM_passphrase = '';
//The identity you're signing as - usually your From address
$mail->DKIM_identity = $mail->From;
//Suppress listing signed header fields in signature, defaults to true for debugging purpose
$mail->DKIM_copyHeaderFields = false;
//Optionally you can add extra headers for signing to meet special requirements
$mail->DKIM_extraHeaders = ['List-Unsubscribe', 'List-Help'];
I am using PHP Mailer (https://github.com/PHPMailer/PHPMailer) and for some reason it is not working with gmail. Does anyone know if there are any other settings I should be using?
function send_email($mail_content,$subject,$email,$name)
{
include_once('third-party/mail/phpmailer-master/PHPMailerAutoload.php');
$php_mailer_mail = new PHPMailer;
$php_mailer_mail->isSMTP();
$php_mailer_mail->Host = 'smtp.gmail.com';
$php_mailer_mail->SMTPAuth = true;
$php_mailer_mail->Username = 'email#gmail.com';
$php_mailer_mail->Password = 'password';
$php_mailer_mail->SMTPSecure = 'ssl';
$php_mailer_mail->Port = 465;
$php_mailer_mail->From = 'email#gmail.com';
$php_mailer_mail->FromName = 'Me';
$php_mailer_mail->addAddress($email, $name);
$php_mailer_mail->isHTML(true);
$php_mailer_mail->Subject = $subject;
$php_mailer_mail->Body = $mail_content;
$php_mailer_mail->send();
}
Make sure you enable IMAP in your gmail settings. smtp is not IMAP, but Google will discard smtp requests for your account unless that is enabled in your account settings.
You may also want to try port 587 with TLS encryption.
Do you get any errors?
if $php_mailer_mail->send(); returns false you may inspect $php_mailer_mail->ErrorInfo
Anyway you should use port 587 and tls instead of ssl.
$php_mailer_mail->Port = 587;
$php_mailer_mail->SMTPSecure = 'tls';
You may take a look at
https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps
Furthermore (from the example at the link above)
SMTP needs accurate times, and the PHP time zone MUST be set
This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
This line must be at the beginning of the script.
Of course double-check username and password.
Hope it helps...
I am using PHPMailer to send a user the results of a form using the following steps:
$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 = "user#example.com";
$mail->Password = "passwd";
$mail->SetFrom("user#example.com");
$mail->Subject = "Test";
$mail->Body = mailMaker($data);
$mail->IsHTML(true);
$mail->AddAddress("otheruser#example.com");
$mail->Send();
This is a part of a larger .php document which is called by ajax and returns the form data back to the page.
When the $mail->Send() function is called the email is sent and everything works fine, but the script ends and I don't get the data back during ajax. I know it is this line because if I comment it out everything works (except the mail isn't sent obviously).
I tried moving the mail methods to another script but I kept getting errors, and was unable to even get a var_dump() or anything returned from the ajax. Is there a logical reason Send() is stopping the script in this case?