簡體   English   中英

PHP-如何將帶有url的變量從表單傳遞到電子郵件程序

[英]PHP- how to pass variable with url in it from form to email program

我一直在努力解決這一問題。 我正在嘗試創建一個簡單的后端電子郵件界面,該界面將允許用戶輸入一些字段,然后郵寄給多個電子郵件收件人。 除了能夠在消息中創建鏈接之外,我已經弄清了大部分內容。 請幫忙。 ps如果有建議使用一種更好的方法,我歡迎他們。謝謝你,詹姆斯。

我的代碼:

$subj = "Try Our New Strawberry Bagels";
$chicken = $_POST['comments'];
$message = $chicken;



 // To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";


 while ($row = mysqli_fetch_assoc($result))
 {
  $emails = $row['email'] . ",";
  mail($emails, $subj, $message, $headers);
 }



?>

<form action="testMail.php" method="post">
                            Name: <input type="text" name="fname" />
                             Age: <input type="text" name="age" />
                           Comment:<textarea name="comments" 
                           id="comments">      </textarea>
                            <input type="submit" />
                            </form>

您將在名稱顯示在數據庫結果中的第一個中添加垃圾信息。 您最有可能希望將mail()調用移到循環的外部,將發送至:

1st loop: a@example.com,
2nd loop: a@example.com, b@example.com,
3rd loop: a@example.com, b@example.com, c@example.com, 
etc...

您還要在郵件標題中指定要發送HTML電子郵件,因此只需使用html指定鏈接即可。

$message = <<<EOL
<a href="http://example.com">Click here</a> for a strawberry bagel deal.
EOL;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM