Answers for "sending mail using phpmailer"

28

php mail

<?php
$to = $_POST['email'];
$subject = "Email Subject";

$message = 'Dear '.$_POST['name'].',<br>';
$message .= "We welcome you to be part of family<br><br>";
$message .= "Regards,<br>";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";

mail($to,$subject,$message,$headers);
?>
Posted by: Guest on May-28-2020
1

php send email

// use this library -> https://github.com/PHPMailer/PHPMailer

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
function sendEmail(){
  	require 'phpmailer/vendor/autoload.php';	

    //Create an instance; passing `true` enables exceptions
    $mail = new PHPMailer(true);
    $mail->CharSet = 'UTF-8';
  try {
      $receiver = '[email protected]';
      $name = 'Name';

      //Server settings
      $mail->SMTPDebug = 1;                      //Enable verbose debug output
      $mail->isSMTP();                                            //Send using SMTP
      $mail->Host       = 'tls://smtp.gmail.com';                     //Set the SMTP server to send through
      $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
      $mail->Username   = '[email protected]';                     //SMTP username
      $mail->Password   = 'PASSWORD';                               //SMTP password
      $mail->SMTPSecure = tls;            //Enable implicit TLS encryption
      $mail->Port       = 587;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

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

      //Content
      $mail->isHTML(true);                                  //Set email format to HTML
      $mail->Subject = 'Subject';
      $mail->Body    = 'Body';

      $mail->send();
      echo 'Message has been sent';
  } catch (Exception $e) {
      echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
  }
}
?>
Posted by: Guest on July-23-2021
0

how to setup php mailer

<?php
    include "emails/PHPMailer/PHPMailerAutoload.php"; 
	//or just include the php mailer class 
    //Create a new PHPMailer instance
    $mail = new PHPMailer(); 

    $mail->IsSMTP(); 
    $mail->SMTPDebug = 1; 
    $mail->SMTPAuth = true; 
    $mail->SMTPSecure = 'ssl'; 
    $mail->Host = "smtp.gmail.com";
	/*
    
    you also need to set the `allow less secure app` = ON 
    in your gmail account which you want to use here 
    :) 
    on then you will be able to send the emails from your account
    using phpMailer
    
    */
    $mail->Port = 465; 
    $mail->IsHTML(true);
    //Username to use for SMTP authentication
    $mail->Username = "@gmail.com";
    $mail->Password = "";
    //Set who the message is to be sent from
    $mail->setFrom('[email protected]', 'Zubair Mushtaq');
    //Set an alternative reply-to address
    $mail->addReplyTo('[email protected]', 'Secure Developer');
    //Set who the message is to be sent to
    $mail->addAddress('[email protected]', 'Abulogicss');
    //Set the subject line
    $mail->Subject = 'PHPMailer SMTP test';
    //Read an HTML message body from an external file, convert referenced images to embedded,
    //convert HTML into a basic plain-text alternative body
    $mail->msgHTML("convert HTML into a basic plain-text alternative body");
    //Replace the plain text body with one created manually
    $mail->AltBody = 'This is a plain-text message body';

    //send the message, check for errors
    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }
Posted by: Guest on April-30-2021

Browse Popular Code Answers by Language