How to send e-mail from localhost with phpmailer?

how to send mail from localhost in php using xampp
how to send mail from localhost in php using phpmailer
how to send mail from localhost in php using wamp
how to configure php mailer
how to send mail in php from localhost
phpmailer localhost xampp
how to send email from localhost in php+ubuntu
how to use mail function in php from localhost

okay, so I already try it for many times. The results was not error but I didn't receive any e-mail in my inbox or spam folder

here is my mail.php

    <?php


require 'phpmailer/PHPMailerAutoload.php';

$mail = new PHPMailer();
//$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "localhost"; // SMTP server
//IsSMTP(); // send via SMTP
$mail->SMTPDebug = true;
$mail->IsSMTP();
$mail->Host     = "smtp.gmail.com"; // SMTP server Gmail
$mail->Mailer   = "gmail";
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'tls'; 
$mail->Port = 587;   


$mail->Username = "henrikus.antony@gmail.com"; // 
$mail->Password = "******"; // SMTP password
$webmaster_email = "henrikus.antony@gmail.com"; //Reply to this email ID
$email = "rikunime.share@gmail.com"; // Recipients email ID
$name = "Hendrikus Anthony"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Anthony";
$mail->AddAddress($email,$name);
$mail->AddReplyTo($webmaster_email,"Anthony");
$mail->WordWrap = 50; // set word wrap

$mail->IsHTML(true); // send as HTML
$mail->Subject = "Ini adalah Email HTML";
$mail->Body = "Ini adalah email contoh"; //HTML Body
$mail->AltBody = "This is the body when user views in plain text format"; //Text Body 
if(!$mail->Send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent";
}
?>

please someone, I really need help. do I need a hosting? or there are something wrong with my syntax? whether sendmail.ini and php.ini affect the mail.php?

Here is my solution which I found out from couple of articles.

<?php

require_once "vendor/autoload.php";

$mail = new PHPMailer;

//Enable SMTP debugging. 
$mail->SMTPDebug = 3;                               
//Set PHPMailer to use SMTP.
$mail->isSMTP();            
//Set SMTP host name                          
$mail->Host = "smtp.gmail.com";
//Set this to true if SMTP host requires authentication to send email
$mail->SMTPAuth = true;                          
//Provide username and password     
$mail->Username = "name@gmail.com";                 
$mail->Password = "password";                           
//If SMTP requires TLS encryption then set it
//$mail->SMTPSecure = "tls";                           
//Set TCP port to connect to 
$mail->Port = 587;                                   

$mail->From = "name@gmail.com";
$mail->FromName = "Full Name";

$mail->smtpConnect(
    array(
        "ssl" => array(
            "verify_peer" => false,
            "verify_peer_name" => false,
            "allow_self_signed" => true
        )
    )
);

$mail->addAddress("reciever@ymail.com", "Recepient Name");

$mail->isHTML(true);

$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    echo "Message has been sent successfully";
}

This won't require any server settings on your localhost.

$mail->smtpConnect(
    array(
        "ssl" => array(
            "verify_peer" => false,
            "verify_peer_name" => false,
            "allow_self_signed" => true
        )
    )
); 

This part of code asks smtp not to verify any connection and can send the mail without verifying the sender. Also you need to enable IMAP settings from your mailbox settings.

Here are the links for reference. https://www.sitepoint.com/sending-emails-php-phpmailer/ https://github.com/PHPMailer/PHPMailer/issues/368#issuecomment-75821110

Using phpmailer sending Emails in PHP from localhost with SMTP , Using phpmailer sending Emails in PHP from localhost with SMTP Download PHPMailer Duration: 11:09 Posted: Dec 20, 2017 PHPMailer supports several ways of sending an email: mail(), Sendmail, Qmail & direct to SMTP servers. You can use any feature of SMTP-based e-mail, multiple recipients, etc. In short, we can say that PHPMailer is an efficient way to send an e-mail within PHP. In this tutorial you will learn howto: - create contact form

You need an SMTP server to send out mail. Assuming you want to use this for testing purposes, try downloading a free SMTP local server such as this one.

If you want to actually send out mail in a production environment, consider using an external service such as SendGrid or MailChimp. Alternatively, if you want to stick with SMTP, you are going to need your own web server to send mail from.

PHP Tutorial: How To Send Email From Localhost Using PHPMailer , PHPMailer supports several ways of sending an email: mail(), Sendmail, Qmail & direct to Duration: 23:00 Posted: Feb 18, 2019 Using PHP to send e-mail messages. There are several ways you can send e-mail messages from your hosting account by using PHP. Learn more in this article. Using Python to send e-mail messages. Learn how to send e-mail messages from your hosting account using Python. Using Git with Plesk. Plesk supports integration with the Git version control

You shouldn't comment out the line that tells the mailer to use smtp except you really want to use the normal mail function,which i don't think you want to

<?php
 require 'PhpMailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
    $mail = new PHPMailer;   
    $mail->isSMTP();
// change this to 0 if the site is going live
    $mail->SMTPDebug = 2;
    $mail->Debugoutput = 'html';
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 587;
    $mail->SMTPSecure = 'tls';

 //use SMTP authentication
    $mail->SMTPAuth = true;
//Username to use for SMTP authentication
    $mail->Username = "xxxxxx@gmail.com";
    $mail->Password = "******";
    $mail->setFrom('xxx@ww.com', 'Somebody');
    $mail->addReplyTo('xxx@ww.com', 'Somebody');
    $mail->addAddress('xxx@ww.com', 'Somebody');
    $mail->Subject = 'New contact from somebody';
    // $message is gotten from the form
    $mail->msgHTML($message);
$mail->AltBody = $filteredmessage;
    if (!$mail->send()) {
        echo "We are extremely sorry to inform you that your message
could not be delivered,please try again.";
    } else {
        echo "Your message was successfully delivered,you would be contacted shortly.";
        }
?> 

please note you must be connected to the internet for gmail's smtp to work

How to Send Email From Localhost using PHP Mailer Library , In this video you will learn how to send email from localhost, How to configure php mailer Duration: 19:21 Posted: Oct 6, 2018 Sending mail using SMTP from localhost using PHPMailer March 28, 2014 Raj Amal PHP 28 Comments When you are testing your Web application in localhost or if you are using W‌indows Operating System it is difficult to setup mail server to send email.

Sending Emails in PHP, PHPMailer; What else should you know about PHP mail sending send emails via localhost and Xmapp; include several recipients with “$to”� Steps to Send E-mail Using PHPMailer Create email address and password from Cpanel Create PHP file to send email with name index.php 1.

How to Use PHPMailer: Examples, Debugging, SMTP Settings, How to send test messages with PHPMailer? server host ($mail->Host = 'smtp.mailtrap.io') username ($mail->Username = '1a2b3c4d5e6f7g' (example, generated by Mailtrap) password ($mail->Password = '1a2b3c4d5e6f7g' (example, generated by Mailtrap) and port ($mail->Port = 25, or 465, or 2525). In this post I'm going to show you how to send mail with a contact form using Bootstrap 4, PHP, PHPMailer library and Gmail SMTP. Here I'll use Gmail as outgoing SMTP server in PHPMailer library and I'll use Bootstrap 4 for contact form design.

How to send an email using PHPMailer ?, Express.js res.send() Function � How to send HTTP response code in PHP? How to configure XAMPP to send mail from localhost using PHP ? Laravel And PHPMailer Send Email From Localhost. You may come up to an idea of adding mail functionality to your Laravel app. We've tried some solution and we think Laravel and PHPMailer is a perfect combination worth to try.

Comments
  • None of the answers use "localhost" please change the title of the question.
  • Can't we use the smtp server provided by gmail ? Or am I confused ?
  • Are you referring to this? Because yes, you can use that.
  • yes, I connected to internet. then when I try it again with your syntax, it said "We are extremely sorry to inform you that your message could not be delivered,please try again."
  • @HenrikusAnthony i lifted this off a script i used barely 13 hours ago,and i also just tested again.it worked,something might just be wrong with your connection or you can try another port,say 465,$mail->Port = 465;