如何将 if 语句放入 PHPMailer 代码的主体中?
How do I put an if statement inside the body of a PHPMailer code?
我试图将 if 语句与 html 一起放入正文中,但它不起作用。我正在使用 PHPMailer,代码有问题吗?
<?php
require 'email/PHPMailerAutoload.php';
extract($_POST);
$mail = new PHPMailer;
$mail ->isHTML(true);
$mail ->CharSet = 'UTF-8';
$mail ->Body .="
if($result != null){
echo "Name: " $result
}
";
我按照 Artem Medianyk 所说的方式进行了尝试,它起作用了,但是当我按照这种方式放置其他变量时,它不起作用。
$body = '';
if ($result_SRV_AA_A10_name_go != null) {
$body = "Name: " . $result_SRV_AA_A10_name_go;
}
if ($result_SRV_AA_A10_email_go != null) {
$body = "E-mail: " . $result_SRV_AA_A10_email_go;
}
if ($result_SRV_AA_A10_tel_go != null) {
$body = "Telefone: " . $result_SRV_AA_A10_tel_go;
}
if ($result_SRV_AA_B9_name_go != null) {
$body = "Name: " . $result_SRV_AA_B9_name_go;
}
if ($result_SRV_AA_B9_email_go != null) {
$body = "E-mail: " . $result_SRV_AA_B9_email_go;
}
if ($result_SRV_AA_B9_tel_go != null) {
$body = "Telefone: " . $result_SRV_AA_B9_tel_go;
}
$body = json_encode($body);
$mail ->Body .= $body;
我的想法是检查已填写的答案,然后通过电子邮件以最佳方式发送。我该怎么做才能实现这一目标?
请试试这个:
<?php
require 'email/PHPMailerAutoload.php';
extract($_POST);
$result = {something};
$mail = new PHPMailer;
$mail ->isHTML(true);
$mail ->CharSet = 'UTF-8';
$body = "";
if ($result != null) {
$body = "Name: " . $result;
}
$body = json_encode($body);
$mail ->Body .= $body;
请再试一次:
$body = '';
if ($result_SRV_AA_A10_name_go != null) {
$body .= "Name: " . $result_SRV_AA_A10_name_go;
}
if ($result_SRV_AA_A10_email_go != null) {
$body .= "E-mail: " . $result_SRV_AA_A10_email_go;
}
if ($result_SRV_AA_A10_tel_go != null) {
$body .= "Telefone: " . $result_SRV_AA_A10_tel_go;
}
if ($result_SRV_AA_B9_name_go != null) {
$body .= "Name: " . $result_SRV_AA_B9_name_go;
}
if ($result_SRV_AA_B9_email_go != null) {
$body .= "E-mail: " . $result_SRV_AA_B9_email_go;
}
if ($result_SRV_AA_B9_tel_go != null) {
$body .= "Telefone: " . $result_SRV_AA_B9_tel_go;
}
$mail ->Body .= $body;
我试图将 if 语句与 html 一起放入正文中,但它不起作用。我正在使用 PHPMailer,代码有问题吗?
<?php
require 'email/PHPMailerAutoload.php';
extract($_POST);
$mail = new PHPMailer;
$mail ->isHTML(true);
$mail ->CharSet = 'UTF-8';
$mail ->Body .="
if($result != null){
echo "Name: " $result
}
";
我按照 Artem Medianyk 所说的方式进行了尝试,它起作用了,但是当我按照这种方式放置其他变量时,它不起作用。
$body = '';
if ($result_SRV_AA_A10_name_go != null) {
$body = "Name: " . $result_SRV_AA_A10_name_go;
}
if ($result_SRV_AA_A10_email_go != null) {
$body = "E-mail: " . $result_SRV_AA_A10_email_go;
}
if ($result_SRV_AA_A10_tel_go != null) {
$body = "Telefone: " . $result_SRV_AA_A10_tel_go;
}
if ($result_SRV_AA_B9_name_go != null) {
$body = "Name: " . $result_SRV_AA_B9_name_go;
}
if ($result_SRV_AA_B9_email_go != null) {
$body = "E-mail: " . $result_SRV_AA_B9_email_go;
}
if ($result_SRV_AA_B9_tel_go != null) {
$body = "Telefone: " . $result_SRV_AA_B9_tel_go;
}
$body = json_encode($body);
$mail ->Body .= $body;
我的想法是检查已填写的答案,然后通过电子邮件以最佳方式发送。我该怎么做才能实现这一目标?
请试试这个:
<?php
require 'email/PHPMailerAutoload.php';
extract($_POST);
$result = {something};
$mail = new PHPMailer;
$mail ->isHTML(true);
$mail ->CharSet = 'UTF-8';
$body = "";
if ($result != null) {
$body = "Name: " . $result;
}
$body = json_encode($body);
$mail ->Body .= $body;
请再试一次:
$body = '';
if ($result_SRV_AA_A10_name_go != null) {
$body .= "Name: " . $result_SRV_AA_A10_name_go;
}
if ($result_SRV_AA_A10_email_go != null) {
$body .= "E-mail: " . $result_SRV_AA_A10_email_go;
}
if ($result_SRV_AA_A10_tel_go != null) {
$body .= "Telefone: " . $result_SRV_AA_A10_tel_go;
}
if ($result_SRV_AA_B9_name_go != null) {
$body .= "Name: " . $result_SRV_AA_B9_name_go;
}
if ($result_SRV_AA_B9_email_go != null) {
$body .= "E-mail: " . $result_SRV_AA_B9_email_go;
}
if ($result_SRV_AA_B9_tel_go != null) {
$body .= "Telefone: " . $result_SRV_AA_B9_tel_go;
}
$mail ->Body .= $body;