我在使用PHPmailer时遇到问题。我使用一个表单并使用$ mail-> Body创建多行以通过PHPmailer发送,如下所示:
<?php
use PHPMailer\PHPMailer\PHPMailer;
include_once "PHPMailer/PHPMailer.php";
include_once "PHPMailer/Exception.php";
include_once "PHPMailer/SMTP.php";
header('Content-Type: text/html; charset=Windows-1252');
$message = "";
$content = "";
if (isset($_POST['submit'])) {
$naam = $_POST['naam'];
$adres = $_POST['adres'];
$woonplaats = $_POST['woonplaats'];
$land = $_POST['land'];
$email = $_POST['email'];
$aantal = $_POST['aantal'];
$verzenden = $_POST['verzenden'];
$opmerkingen = $_POST['opmerkingen'];
$jaar = substr(date("y"),-1);
if ($verzenden == "afhalen"){
$verzendkosten = "0.00";
} else {
$verzendkosten = "6.50";
}
$subtotaal = $aantal * 37.50;
$totaal = $subtotaal + $verzendkosten;
$BTW = $totaal * 0.173554;
$weergavetotaal = number_format($totaal, 2, ',', '.');
$weergavesubtotaal = number_format($subtotaal, 2, ',', '.');
$weergaveBTW = number_format($BTW, 2, ',', '.');
$weergaveverzendkosten = number_format($verzendkosten, 2, ',', '.');
// IP van de verstuurder
$ip = '';
if (getenv('HTTP_CLIENT_IP'))
$ip = getenv('HTTP_CLIENT_IP');
else if(getenv('HTTP_X_FORWARDED_FOR'))
$ip = getenv('HTTP_X_FORWARDED_FOR');
else if(getenv('HTTP_X_FORWARDED'))
$ip = getenv('HTTP_X_FORWARDED');
else if(getenv('HTTP_FORWARDED_FOR'))
$ipa = getenv('HTTP_FORWARDED_FOR');
else if(getenv('HTTP_FORWARDED'))
$ip = getenv('HTTP_FORWARDED');
else if(getenv('REMOTE_ADDR'))
$ip = getenv('REMOTE_ADDR');
else
$ip = 'ONBEKEND';
$factuurip = substr($ip,-2);
$factuurmin = substr(date('i'),-1);
$content = "" .$naam. "<br>";
$content .= "" .$adres. "<br>";
$content .= "" .$woonplaats. "<br>";
$content .= "" .$land. "<br>";
$content .= "e-Mail: " .$email. "<br> <br> <br>";
$content .= "FACTUUR <br> <br>";
$content .= "Factuurdatum: ".date("j-m-Y")."<br>";
$content .= "Factuurnummer: " .$jaar. "" .date("md"). "-" .$factuurip. "" .$factuurmin. "<br> <br> <br>";
$content .= "Hartelijke dank voor de volgende bestelling: <br>";
$content .= "_________________________________________________________________________ <br> <br>";
$content .= "" .$aantal. " Stuk(s) Siberisch Stenenorakel a 37,50 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . € " .$weergavesubtotaal. "<br> <br>";
$content .= "Bijdrage in de verzendkosten . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . € " .$weergaveverzendkosten. "<br>";
$content .= "Levering: ".$verzenden." <br> <br>";
$content .= "_________________________________________________________________________ <br> <br>";
$content .= "BTW 21% € " .$weergaveBTW. " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Totaal € " .$weergavetotaal. "<br> <br> <br>";
$content .= "Uw bestelling is definitief zodra het totaalbedrag van € " .$weergavetotaal. " <br>";
$content .= "is ontvangen o.v.v. het bovenstaande factuurnummer* <br> <br>";
$content .= "Uw opmerkingen: <br>";
$content .= "" .$opmerkingen. "<br> <br>";
$content .= "*Zonder tegenbericht bedraagt de levertermijn enkele dagen. <br>";
$content .= "*Afhalen alleen op afspraak. Bij afhalen is PIN-betaling mogelijk. <br>";
$content .= "Dit formulier is ingevuld vanaf IP-nummer " .$ip. " op ".date("j M Y")." om ".date("G:i")."<br> <br>";
$message = $content;
$mail = new PHPMailer();
//if we want to send via SMTP
$mail->Host = "smtp.mail.pcextreme.nl";
//$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Username = "mail@domain.com";
$mail->Password = "passsword";
$mail->SMTPSecure = "TLS"; //SSL
$mail->Port = 587; //465
$mail->addAddress($email, $naam);
$mail->setFrom('mail@domain.com');
$mail->Subject = "Bestelling Siberisch Stenenorakel";
$mail->isHTML(true);
$mail->Body = $message;
if ($mail->send()) {
echo $message;
}
}
?>
当我将其回显到屏幕上时,它看起来不错,但是只有当我使用不超过3行时,它才会发送。哪三行都没关系。有什么建议么? Gr Jabson
更新:我现在发布了完整的代码。屏幕上的回声还可以,但是仅当我将行数限制为最大时才发送邮件。 3. Gr Jabson
答案 0 :(得分:0)
不确定为什么要根据您提供的内容发生问题,但是在将变量分配给邮件正文之前完全定义变量可以解决问题,或者至少可以缩小问题范围。
$message = 'content<br>';
$message .= 'more content<br>';
$message .= 'yet content<br>';
$mail->Body = $message;
答案 1 :(得分:0)
好的,我知道问题是什么:当我将PHP降级到5.6时,它可以正常工作。问题仅在于PHP 7.1和7.2与PHPmailer。
当我只发送文本时,没有问题。但是,当其中包含一些
和@时,不会发送邮件。
但是如前所述,使用5.6没问题。目前,此问题已解决,当我的Providere不再提供5.6时,可能会进行更新。