首先,我对 PHP 和电子邮件有些陌生,但如果用户有或没有选中输入框,我需要能够发送两个电子邮件模板。电子邮件功能有效并且一直有效,但我完全不知道如何使用 If Else 语句来交换模板。我的问题是,为什么我的控制台没有给我错误但它不再发送了。
需要的路径...
- 用户没有发票(检查输入框)> 切换到模板 1
用户有发票 > 切换到模板 2
<p style="margin-top: 10px;"> If you do not not your Invoice Number please check this box. <input id="check" name="check" type="checkbox" /> </p> ------------------------------------------------------------ <?php $to = $_POST['email']; $subject = 'Subject ' . $_POST['invoice_name'] . ' ' . $_POST['invoice_year'] . ' - ' . $_POST['invoice_number']; $header = "From: support@website.com" . "\r\n"; $header .= "Reply-To: support@website.com" . "\r\n"; $header .= "MIME-Version: 1.0" . "\r\n"; $header .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $message = if(isset($_POST['check']) { $message = '<html> <body> <h2>Email Template 2</h2> <p> Donec sed odio dui. Curabitur blandit tempus porttitor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.</p> <p><b>Name: </b>' . $_POST['first_name'] . ' ' . $_POST['last_name'] . '</p> <p><b>Invoice #: </b>' . $_POST['invoice_name'] . ' ' . $_POST['invoice_year'] . ' - ' . $_POST['invoice_number'] . '</p> <p><b>Date: </b>' . $today = date("F j, Y, g:i a") . '</p> <p><b>Card Used: </b> XXXX-XXXX-XXXX-' . $charge->card->last4 . '</p> <p><b>Payment Amount: </b>$' . $_POST['price'] . '</p> <br/> <p><b>Reminder:</b> Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p> <br/> <p>http://www.website.com/payment</p> </body> </html>'; } else { $message = '<html> <body> <h2>Email Template 2</h2> <p> Donec sed odio dui. Curabitur blandit tempus porttitor. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.</p> <p><b>Name: </b>' . $_POST['first_name'] . ' ' . $_POST['last_name'] . '</p> <p><b>Invoice #: </b>' . $_POST['invoice_name'] . ' ' . $_POST['invoice_year'] . ' - ' . $_POST['invoice_number'] . '</p> <p><b>Date: </b>' . $today = date("F j, Y, g:i a") . '</p> <p><b>Card Used: </b> XXXX-XXXX-XXXX-' . $charge->card->last4 . '</p> <p><b>Payment Amount: </b>$' . $_POST['price'] . '</p> <br/> <p><b>Reminder:</b> Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p> <br/> <p>http://www.website.com/payment</p> </body> </html>'; }; mail($to, $subject, $message, $header); ?>
这是一种更简单的查看方式。
<?php if(isset($_POST['check']) {
$message = ' HAS NO INVOICE ';
} else {
$message = '';
};
mail($to, $subject, $message, $header);
?>