我有一个注册表单,允许用户注册并成为我网站上的成员。到目前为止,一旦他们注册了他们的详细信息,这将进入数据库,他们会收到一封电子邮件,表示感谢。
我正在尝试复制脚本,以便我可以发送不同的电子邮件,让我知道用户何时注册并将其发送到我的电子邮件。
我正在尝试这样做,因为发送给用户的电子邮件包含随机生成的md5哈希码,我也需要在发送给我的电子邮件中发送给我,告诉我他们已注册
我设法将这两封电子邮件发送到正确的电子邮件帐户。然而,发送给我的电子邮件让我知道用户已经注册了也发送给用户,我不希望它发送给他们?
有谁可以建议我哪里出错了?感谢
CODE向用户发送电子邮件:
<?php
/**
* ShuttleCMS - A basic CMS coded in PHP.
* code generator - Used for allowing a user to generate a code
*
* @author Dan <dan@danbriant.com>
* @version 0.0.1
* @package ShuttleCMS
*/
define('IN_SCRIPT', true);
// Start a session
session_start();
/*
* Generates new code and puts it on database
*/
//Generate a RANDOM MD5 Hash for a code
$random_code=md5(uniqid(rand()));
//Take the first 8 digits and use them as the password we intend to email the user
$emailcode=substr($random_code, 0, 8);
//Encrypt $emailpassword in MD5 format for the database
$registrationcode=($emailcode);
// Make a safe query
$query = sprintf("UPDATE `ptb_registrations` SET `registration_code` = '%s' WHERE email = \"$email\"",
mysql_real_escape_string($registrationcode));
mysql_query($query)or die('Could not update members: ' . mysql_error());
?>
<?php
$subjectconfirm = " Thanks for your Registration";
$headersconfirm = "To: $email\r\n";
$headersconfirm .= "From: siteindex.com <registrations@siteindex>\r\n";
$headersconfirm .= "Content-type: text/html\r\n";
$sep = sha1(date('r', time()));
$bodyconfirm = <<< EOF
(EMAIL BODY)
EOF;
// Finally, send the email
mail($email, $subjectconfirm, $bodyconfirm, $headersconfirm);
?>
然后我复制这样的代码,但替换为电子邮件地址。它发送到我的电子邮件帐户很好,但它发送两封电子邮件给用户,我不希望他们收到给我的电子邮件。
发送电子邮件给我的代码:
<?php
/**
* ShuttleCMS - A basic CMS coded in PHP.
* code generator - Used for allowing a user to generate a code
*
* @author Dan <dan@danbriant.com>
* @version 0.0.1
* @package ShuttleCMS
*/
define('IN_SCRIPT', true);
// Start a session
session_start();
/*
* Generates new code and puts it on database
*/
//Generate a RANDOM MD5 Hash for a code
$random_code=md5(uniqid(rand()));
//Take the first 8 digits and use them as the password we intend to email the user
$emailcode=substr($random_code, 0, 8);
//Encrypt $emailpassword in MD5 format for the database
$registrationcode=($emailcode);
// Make a safe query
$query = sprintf("UPDATE `ptb_registrations` SET `registration_code` = '%s' WHERE email = \"$email\"",
mysql_real_escape_string($registrationcode));
mysql_query($query)or die('Could not update members: ' . mysql_error());
?>
<?php
$subjectconfirm = " Thanks for your Registration";
$headersconfirm = "To: signups@siteindex.com\r\n";
$headersconfirm .= "From: siteindex.com <signups@siteindex>\r\n";
$headersconfirm .= "Content-type: text/html\r\n";
$sep = sha1(date('r', time()));
$bodyconfirm = <<< EOF
(DIFFERENT EMAIL BODY)
EOF;
// Finally, send the email
mail($email, $subjectconfirm, $bodyconfirm, $headersconfirm);
?>
答案 0 :(得分:3)
您会从mail manual page注意到,第一个参数是电子邮件发送到的位置。你没有改变它。您只更改了标题。要向其他人发送电子邮件,请更改:
mail($email, $subjectconfirm, $bodyconfirm, $headersconfirm);
为:
mail('signups@siteindex.com', $subjectconfirm, $bodyconfirm, $headersconfirm);
当然,对自己进行BCC而不是复制所有这些代码更为明智。
答案 1 :(得分:0)
我认为不需要复制代码。只需发送两封电子邮件:
$emails = 'youremail@email.com, theiremail@email.com';
mail($emails, $subjectconfirm, $bodyconfirm, $headersconfirm);
或自己BCC:
$headersconfirm .= 'Bcc: youremail@email.com' . "\r\n";
看看here。