简体   繁体   English

PHP-如何将带有url的变量从表单传递到电子邮件程序

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

I've been trying to figure this out all day. 我一直在努力解决这一问题。 I'm trying to create a simple back-end email interface that will allow user to enter a few fields and then mail off to several email recipients. 我正在尝试创建一个简单的后端电子邮件界面,该界面将允许用户输入一些字段,然后邮寄给多个电子邮件收件人。 I have figured out most of it with the exception of being able to create a link in the message. 除了能够在消息中创建链接之外,我已经弄清了大部分内容。 Please help. 请帮忙。 ps If there are suggestions for an entirely better way to do this, I'm open to them.Thank you, james. ps如果有建议使用一种更好的方法,我欢迎他们。谢谢你,詹姆斯。

my code: 我的代码:

$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>

You're going to be spamming the heck out of the first whose name shows up in the database results. 您将在名称显示在数据库结果中的第一个中添加垃圾信息。 Most likely you'd want to move the mail() call OUTSIDE of your loop, you'll be sending to: 您最有可能希望将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...

You're also specifying in the mail headers that you're sending an HTML email, so just use html to specify the link. 您还要在邮件标题中指定要发送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