问题
I have a strange issue with PHPMailer, when I try to send an email I see this error: escapeshellcmd() has been disabled for security reasons
but if I check the email, I can see that the email is sent, how can I fix/hide this problem?
回答1:
Use this code that's it, hope it will help:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
$mail = new PHPMailer(true);
$name = 'Your Name';
$to = 'to@gmail.com';
$subject = 'Hello World!';
$message = 'This is a test mail!';
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = 'yourmail@gmail.com';
$mail->Password = '*********';
$mail->SMTPSecure = 'tls';
$mail->addReplyTo($to, $name);
$mail->setFrom($to, $name);
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->msgHtml($message);
$mail->send();
Simply change email & password and run.
Hope you included PHPMailer library in root, if no then also check the path.
Thanks!
回答2:
Your PHP installation has disabled that function, but it's probably a warning rather than an error so it's continuing to run your code and sending your mail. You control the display of PHP errors & warnings in your php.ini file, look at the error_display
property.
A better solution is to use SMTP to localhost, which does not require the use of this function. It's also faster and safer than using PHP's mail()
function, which is what PHPMailer uses by default. To change, just add this to your existing PHPMailer code:
$mail->isSMTP();
$mail->Host = 'localhost';
来源:https://stackoverflow.com/questions/51213177/phpmailer-semi-issue