简体   繁体   中英

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("JohnMiller@example.com\r\n", "Web site");
$mail->addAddress("DorothyBaker@example.com");
$mail->Subject = "Thank you for your order";
$mail->Body = "Your package will arrive soon.";
$mail->send();
?>

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM