2012-12-07 76 views
0

我有一个注册表格,允许用户注册并成为我网站上的会员。到目前为止,一旦他们注册了他们的详细信息,就会在数据库中发送,并且他们会收到一封电子邮件,表示感谢发送2个不同的电子邮件给2个不同的收件人?

我想复制脚本,以便我可以发送不同的电子邮件,让我知道用户何时注册并将其发送到我的电子邮件。

我试图这样做,因为发送给用户的电子邮件包含一个随机生成的md5哈希代码,我还需要发送给我的邮件发送给我,告诉我他们已经注册。

我设法让两封电子邮件发送到正确的电子邮件帐户。然而,发送给我的电子邮件让我知道用户已经注册,也正在发送给用户,我不想让他们去看他们?

任何人都可以建议我要去哪里错了吗?由于

代码来发送电子邮件给用户:

<?php 

/** 
* ShuttleCMS - A basic CMS coded in PHP. 
* code generator - Used for allowing a user to generate a code 
* 
* @author Dan <[email protected]> 
* @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 <[email protected]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 <[email protected]> 
    * @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 protected]\r\n"; 
    $headersconfirm .= "From: siteindex.com <[email protected]>\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

很多代码。只需通过他们的电子邮件发送给用户。然后发送给你自己,与您的电子邮件 – Ibu

+0

谢谢你能够解释一下你的意思,就像一个例子,如果可能的话谢谢。 –

+1

你可以只为自己打电话,以便只需发送一封电子邮件? – David

回答

3

你会从mail manual page注意到,第一个参数是在发送电子邮件到。你没有改变它。您只更改了标题。为了发送电子邮件给别人,变化:

mail($email, $subjectconfirm, $bodyconfirm, $headersconfirm); 

到:

mail('[email protected]', $subjectconfirm, $bodyconfirm, $headersconfirm); 

当然,这是更为明智的做法只是BCC它自己,而不是重复所有这些代码。

+0

谢谢你解决了它:) –

0

我看不到需要复制代码。只需发送两封电子邮件:

$emails = '[email protected], [email protected]'; 
mail($emails, $subjectconfirm, $bodyconfirm, $headersconfirm); 

或者BCC自己:

$headersconfirm .= 'Bcc: [email protected]' . "\r\n"; 

看看here

+0

包括'youremail @ email.com'作为BCC收件人可能比TO收件人更可取,但除此之外你是正确的......没有必要在这里复制任何代码。 – David

相关问题