'Sending E-Mail from PHP with PHPMailer
I'm trying to send this email message from the localhost on my computer, but it doesn't do anything. Do I need a Mailer Server to send it? Can it be done in the development environment for testing?
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'autoload.php';
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = false;
$mail->setFrom("[email protected]\r\n", "Web site");
$mail->addAddress("[email protected]");
$mail->Subject = "Thank you for your order";
$mail->Body = "Your package will arrive soon.";
$mail->send();
?>
Solution 1:[1]
You cannot send an email like this from local host.Need an email server.If you want to make this work, you have to do a hell lot of work.
Solution 2:[2]
The easiest way to set this up for development is to use a fake mail server such as HELO (no affiliation, I'm just a happy user).
In production, it can be extremely simple to set up the basics. On Debian-based Linux distros, a simple apt install postfix will work with all default settings. Tuning it up and making it work nicely, DKIM signing, SPF, etc, is more involved, and if you don't like the sound of that, take a look at commercial SMTP providers such as Amazon SES, mailgun, smtp.com.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | arun s r |
| Solution 2 | Synchro |
