这是我的代码。我想知道为什么没有发送电子邮件。
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';
$messaggio = new PHPmailer();
$messaggio->isSMTP();
//settiamo su true il metodo che indica alla classe
//il formato HTML
$messaggio->IsHTML(true);
$messaggio->Charset = 'UTF-8';
$messaggio->Host='mail.example.com';
$messaggio->SMTPSecure = '';
$messaggio->SMTPAuth = true;
$messaggio->Username = 'webmaster@example.com';
$messaggio->Password = 'AM19720306*';
$messaggio->Port = 25;
//intestazioni e corpo dell'email
$messaggio->From='webmaster@example.com';
$messaggio->FromName = "Webmaster";
$messaggio->AddAddress('amaranga72@hotmail.com');
$messaggio->AddReplyTo('webmaster@example.it');
$messaggio->Subject='Benvenuto Nel Nostro Sito';
//inseriamo i tag HTML e i CSS per formattare il messaggio
$messaggio->Body = '<html><body><head><style>';
$messaggio->Body .= '.up{background-color:#FF0000;color:#000000;font- size:12px;font-weight:bold}';
$messaggio->Body .= '.down{color:#FF0000;text-align:left;font-size:12px}';
$messaggio->Body .= '</style></head>';
$messaggio->Body .= '<img '
. 'src="/http://localhost/home/albertyno/NetBeansProjects/PhpMail/TecnoLogo2Rid.gif.jpg" alt="logo TS"/>';
$messaggio->Body .= '<center><table><tr><td class="up">Buongiorno Utente</td></tr>';
$messaggio->Body .= '<tr><td class="down">ciao!!!</td></tr></table></center>';
$messaggio->Body .= '<table><tr><td style="font-weight:bold">Alberto Marangoni</td></tr>';
$messaggio->Body .= '<tr><td>Via Manzoni, 9</td></tr>';
$messaggio->Body .= '<tr><td>20080 Vermezzo (MI)</td></tr>';
$messaggio->Body .= '<tr><td>Tel.: 0248403353</td></tr>';
$messaggio->Body .= '<tr><td>Fax : 0248400342</td></tr>';
$messaggio->Body .= '<tr><td>Cell: 327.......</td></tr>';
$messaggio->Body .= '<tr><td>Email: alberto-marangoni@tecno02.com</td></tr>';
$messaggio->Body .= '</body></html>';
//parte relativa all'invio
if(!$messaggio->Send()){
echo $messaggio->ErrorInfo;
}else{
echo 'Email inviata correttamente!';
}
我使用后缀和phpmailer。
我在做什么错了?
答案 0 :(得分:0)
我认为它不起作用,因为您没有设置真实的电子邮件,我在代码中看到From='webmaster@example.com';
。因此,我建议您首先将其更改为通过您的域发送电子邮件,然后调整代码中的所有参数。
我们无法向您发送已解决的代码,因为我们不知道您的域,电子邮件等。
希望对您有所帮助:)
谢谢,奥利弗
答案 1 :(得分:0)
这是SMTP给我的错误:
2019-01-20 07:25:57 Connection: opening to mail.example.com:25, timeout=300, options=array()
2019-01-20 07:25:57 Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known [/home/albertyno/NetBeansProjects/PhpMail/vendor/phpmailer/phpmailer/src/SMTP.php line 326]
2019-01-20 07:25:57 Connection failed. Error #2: stream_socket_client(): unable to connect to mail.example.com:25 (php_network_getaddresses: getaddrinfo failed: Name or service not known) [/home/albertyno/NetBeansProjects/PhpMail/vendor/phpmailer/phpmailer/src/SMTP.php line 326]
2019-01-20 07:25:57 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
2019-01-20 07:25:57 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting.
您能解决吗?