Dismiss Notice

Register now to be one of the first members of this SharePoint Community! Click here it just takes seconds!

Dismiss Notice
Welcome Guest from Country Flag

Send email on App Service using PHP Mailer and O365

Discussion in 'Official Microsoft News' started by Mangesh Sangapu, Mar 27, 2017.

Thread Status:
Not open for further replies.
  1. Mangesh Sangapu

    Mangesh Sangapu Guest

    Blog Posts:
    This is a Proof of Concept to send email using the PHP Mailer library and 0365.

    From the PHPMailer GitHub site, follow the “Minimal installation” section and download class.phpmailer.php and class.smtp.php.

    Copy-paste the code from “A Simple Example” section or use the following:

    require 'class.phpmailer.php';
    require 'class.smtp.php';

    $mail = new PHPMailer;

    //$mail->SMTPDebug = 3; // Enable verbose debug output

    $mail->isSMTP(); // Set mailer to use SMTP
    $mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = '[email protected]'; // SMTP username
    $mail->Password = 'password'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 25; // TCP port to connect to

    $mail->setFrom('[email protected]', 'Name');
    $mail->addAddress('[email protected]'); // Add a recipient

    //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
    $mail->isHTML(true); // Set email format to HTML

    $mail->Subject = 'Here is the subject';
    $mail->Body = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
    echo 'Message has been sent';

    I did the above using kudu, so my folder looked like this:


    And I ran the script from the command-line “php mail.php”.


    Here’s the message that was sent:


    Continue reading...
Thread Status:
Not open for further replies.

Share This Page

LiveZilla Live Chat Software