Php smtp ssl tls

Php smtp ssl tls

Advertisement:
Canagon.com — Website for $499, beautiful premade designs, high-performance hosting on all continents, dedicated support team. Learn more >

Method: Using PHPMailer library

  • use to send e-mail with SMTP over SSL/TLS
  • use to send using your Google Apps Account or Gmail
  • use to send using your Amazon AWS SES account

Download the PHPMailer library from here, https://github.com/Synchro/PHPMailer. It is free, easy to use library that supports sending e-mail using secure connection directly form SMTP. If you run you own virtual or dedicated server and you are not into setting up mailserver application, this is the right PHP library for you.

This library works perfectly with plaint text and HTML or you may create HTML mail and insert an plain text alternative to support older mail clients with no HTML support.

Example, if you have your website on http://www.example.com/ and your document root is /var/www/example.com, upload the phpmailer directory up to /var/www/example.com/scripts/phpmailer.

Читайте также:  Отступы между ячеек таблицы css

Do not forget to escape your $_POST and $_GET variables, always put e-mailing scripts into if statement or at least use some protection to prevent «hackers» from using your page with script mailer as a e-mail spam gateway.

$mail->IsSMTP(); // telling the class to use SMTP

$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = «tls»; // sets the prefix to the servier
$mail->Host = «smtp.gmail.com»; // sets Gmail as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL

$mail->Username = «info@example.com»; // Gmail username
$mail->Password = «yourpassword»; // Gmail password

$mail->CharSet = ‘windows-1250’;
$mail->SetFrom (‘info@example.com ‘, ‘Example.com Information’);
$mail->AddBCC ( ‘sales@example.com ‘, ‘Example.com Sales Dep.’);
$mail->Subject = $subject;
$mail->ContentType = ‘text/plain’;
$mail->IsHTML(false);

// you may also use this format $mail->AddAddress ($recipient);

if(!$mail->Send())
<
$error_message = «Mailer Error: » . $mail->ErrorInfo;
> else

// You may delete or alter these last lines reporting error messages, but beware, that if you delete the $mail->Send() part, the e-mail will not be sent, because that is the part of this code, that actually sends the e-mail.

HTML vs. PLAIN TEXT

To send plain text, here are few tips:

  1. Do not use $mail->MsgHTML($body_of_your_email); instead use $mail->Body = $body_of_your_email;
  2. Do not use $mail->AltBody = ‘Your alternative message to HTML’;
  3. Set $mail->IsHTML(false);

To send HTML e-mail, here are few tips:

  1. Of course set $mail->IsHTML(true); or you don’t have to set this variable at all, by default it is set to true.
  2. For e-mail body use only MsgHTML, for example: $mail->MsgHTML( file_get_contents(‘your_mail_template.html’) );, do not use $mail->Body = $body_of_your_email;

Other TIPs

  • $mail->AddReplyTo(«reply-to@example.com»,»First Last»);
  • $mail->AddAttachment(«path/to/a/file/attachment.gif»);
  • $mail->IsSendmail(); // telling the class to use SendMail transport
  • If not set IsSendmail() and IsSMTP, it uses standard PHP mail();
  • If sending bulk mail, for example many e-mails from a database, use $mail->SMTPKeepAlive = true; for keeping SMTP connection alive, to view a example PHP code, see test_db_smtp_basic.php in examples directory of PHPmail library.
  • To set language, use $mail->SetLanguage(‘de’, ‘phpmailer/language/’); — for list of available languages, look into /language folder of the PHPMailer library.

Why use PHPMailer

I decided to use PHPMailer and not to install mailserver like Postfix, because of security issue, SPAM fighting and also this is a time saver, because I use Google Apps, I set up my Google Apps account to automatically sign e-mails with DKIM, I setup SPF DNS record and the best of all, as I host multiple sites as Virtual Hosts on my web server, I also want to sometimes use different e-mail accounts on different parts of my website, for example part of my website uses Amazon AWS SES, part of my website uses my company SMTP server and part uses Google Apps e-mail accounts, all set in PHP code, nothing to setup on server side.

Advertisement:
Create your website, $499 / year, hosting included, choose your design and domain, enter content we’ll take care of the rest. Learn more >

Website for $499

Canagon — get a website with professional premade design, premium theme, and premium SSD hosting, free SSL. Drag & drop visual builder, transparent pricing, a lot of great features included. Visit Canagon.com and get inspired by live demos of professional designs.

Источник

Php smtp ssl tls

Advertisement:
Canagon.com — Website for $499, beautiful premade designs, high-performance hosting on all continents, dedicated support team. Learn more >

Method: Using PHPMailer library

  • use to send e-mail with SMTP over SSL/TLS
  • use to send using your Google Apps Account or Gmail
  • use to send using your Amazon AWS SES account

Download the PHPMailer library from here, https://github.com/Synchro/PHPMailer. It is free, easy to use library that supports sending e-mail using secure connection directly form SMTP. If you run you own virtual or dedicated server and you are not into setting up mailserver application, this is the right PHP library for you.

This library works perfectly with plaint text and HTML or you may create HTML mail and insert an plain text alternative to support older mail clients with no HTML support.

Example, if you have your website on http://www.example.com/ and your document root is /var/www/example.com, upload the phpmailer directory up to /var/www/example.com/scripts/phpmailer.

Do not forget to escape your $_POST and $_GET variables, always put e-mailing scripts into if statement or at least use some protection to prevent «hackers» from using your page with script mailer as a e-mail spam gateway.

$mail->IsSMTP(); // telling the class to use SMTP

$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = «tls»; // sets the prefix to the servier
$mail->Host = «smtp.gmail.com»; // sets Gmail as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL

$mail->Username = «info@example.com»; // Gmail username
$mail->Password = «yourpassword»; // Gmail password

$mail->CharSet = ‘windows-1250’;
$mail->SetFrom (‘info@example.com ‘, ‘Example.com Information’);
$mail->AddBCC ( ‘sales@example.com ‘, ‘Example.com Sales Dep.’);
$mail->Subject = $subject;
$mail->ContentType = ‘text/plain’;
$mail->IsHTML(false);

// you may also use this format $mail->AddAddress ($recipient);

if(!$mail->Send())
<
$error_message = «Mailer Error: » . $mail->ErrorInfo;
> else

// You may delete or alter these last lines reporting error messages, but beware, that if you delete the $mail->Send() part, the e-mail will not be sent, because that is the part of this code, that actually sends the e-mail.

HTML vs. PLAIN TEXT

To send plain text, here are few tips:

  1. Do not use $mail->MsgHTML($body_of_your_email); instead use $mail->Body = $body_of_your_email;
  2. Do not use $mail->AltBody = ‘Your alternative message to HTML’;
  3. Set $mail->IsHTML(false);

To send HTML e-mail, here are few tips:

  1. Of course set $mail->IsHTML(true); or you don’t have to set this variable at all, by default it is set to true.
  2. For e-mail body use only MsgHTML, for example: $mail->MsgHTML( file_get_contents(‘your_mail_template.html’) );, do not use $mail->Body = $body_of_your_email;

Other TIPs

  • $mail->AddReplyTo(«reply-to@example.com»,»First Last»);
  • $mail->AddAttachment(«path/to/a/file/attachment.gif»);
  • $mail->IsSendmail(); // telling the class to use SendMail transport
  • If not set IsSendmail() and IsSMTP, it uses standard PHP mail();
  • If sending bulk mail, for example many e-mails from a database, use $mail->SMTPKeepAlive = true; for keeping SMTP connection alive, to view a example PHP code, see test_db_smtp_basic.php in examples directory of PHPmail library.
  • To set language, use $mail->SetLanguage(‘de’, ‘phpmailer/language/’); — for list of available languages, look into /language folder of the PHPMailer library.

Why use PHPMailer

I decided to use PHPMailer and not to install mailserver like Postfix, because of security issue, SPAM fighting and also this is a time saver, because I use Google Apps, I set up my Google Apps account to automatically sign e-mails with DKIM, I setup SPF DNS record and the best of all, as I host multiple sites as Virtual Hosts on my web server, I also want to sometimes use different e-mail accounts on different parts of my website, for example part of my website uses Amazon AWS SES, part of my website uses my company SMTP server and part uses Google Apps e-mail accounts, all set in PHP code, nothing to setup on server side.

Advertisement:
Create your website, $499 / year, hosting included, choose your design and domain, enter content we’ll take care of the rest. Learn more >

Website for $499

Canagon — get a website with professional premade design, premium theme, and premium SSD hosting, free SSL. Drag & drop visual builder, transparent pricing, a lot of great features included. Visit Canagon.com and get inspired by live demos of professional designs.

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

This is a simple SMTP PHPMailer. The PHP Class supports TLS, SSL and File Attachments in mail.

halojoy/PHP-SMTP-Mailer

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This is a lightweight SMTP PHPMailer.
The PHP Class supports TLS, SSL and File Attachments in mail.
Simple, powerful and easy to use.

  • Sends mail using one SMTP Server like ‘smtp.gmail.com’.
  • Auth login with username and password.
  • Uses security protocols TLS and SSL.
  • Supports ‘text/html’ or ‘text/plain’ messages.
  • Supports any number of file attachments.
  • Default Charset is ‘UTF-8’ but can be changed.
  • 8bit, 7bit, Binary or Quoted-Printable transfer encoding.
  • Logging of the transaction for debug.
  • From — one email
  • Reply-To — multiple possible
  • To — multiple possible
  • Cc — multiple possible
  • Bcc — multiple possible
  1. Begin with running setup_config.php
    This will store your server connection settings.
  2. After this you can try example_minimal.php
    It is a basic example like this:
 require 'class/SMTPMailer.php'; $mail = new SMTPMailer(); $mail->addTo('someaccount@hotmail.com'); $mail->Subject('Mail message for you'); $mail->Body( '

Mail message

This is a html message. Greetings!' ); if ($mail->Send()) echo 'Mail sent successfully'; else echo 'Mail failure'; ?>

About

This is a simple SMTP PHPMailer. The PHP Class supports TLS, SSL and File Attachments in mail.

Источник

Оцените статью