2012-12-07 5 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]>\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'을 포함하는 것이 TO 수신자보다 바람직하지만 그렇지 않으면 올바른 것입니다. 여기에 코드를 복제 할 필요가 없습니다. – David

관련 문제