簡體   English   中英

向2個不同的收件人發送2個不同的電子郵件?

[英]Send 2 Different Emails to 2 Different Recipients?

我有一個注冊表格,允許用戶注冊並成為我的網站的成員。 到目前為止,一旦他們注冊了詳細信息,它就會進入數據庫,並且會收到一封發送電子郵件以表示感謝。

我正在嘗試復制腳本,以便我可以發送另一封電子郵件,讓我知道用戶何時注冊,並將其發送到我的電子郵件中。

我正在嘗試這樣做,因為發送給用戶的電子郵件包含隨機生成的md5哈希碼,在發送給我的電子郵件中告訴我他們已經注冊,我也需要發送該代碼。

我設法將這兩封電子郵件傳遞到正確的電子郵件帳戶。 但是,發送給我的電子郵件(告訴我用戶已注冊)也發送給該用戶,我不希望發送給他們嗎?

誰能建議我要去哪里錯了? 謝謝

向用戶發送電子郵件的代碼:

<?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);

    ?>

您會在郵件手冊頁上注意到,第一個參數是電子郵件發送到的位置。 您尚未更改。 您只更改了標題。 為了發送電子郵件給其他人,請更改:

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

至:

mail('signups@siteindex.com', $subjectconfirm, $bodyconfirm, $headersconfirm);

當然,僅對自己進行密件抄送而不是復制所有這些代碼更為明智。

我看不到需要重復代碼。 只需發送兩封電子郵件:

$emails = 'youremail@email.com, theiremail@email.com';
mail($emails, $subjectconfirm, $bodyconfirm, $headersconfirm);

還是自己密送:

$headersconfirm .= 'Bcc: youremail@email.com' . "\r\n";

在這里看看。

暫無
暫無

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

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