2012-05-16 2 views
0

다음 프로그램은 들어오는 전자 메일 별칭을 데이터베이스의 전자 메일 별칭과 일치시키고 Craigslist와 같이 올바른 주소로 전자 메일을 전달하기위한 프로그램입니다.Craigslist 만들기 익명 전자 메일 전달 프로그램

지금이 오류가 무엇입니까 : 여기

Error: [1] You must provide at least one recipient email address. 
in anon-email.php at line number: sending the email 

입니다 코드 : 당신의 기능 searchRecipient이 아닌 것으로 생각된다 : 여기

$mailboxinfo = imap_mailboxmsginfo($connection); 
$messageCount = $mailboxinfo->Nmsgs; //Number of emails in the inbox 
for ($MID = 1; $MID <= $messageCount; $MID++) 
    { 
    $EmailHeaders = imap_headerinfo($connection, $MID); //Save all of the header information 
    $Body = imap_qprint(imap_fetchbody($connection, $MID, 1)); //The body of the email to be forwarded 

    $MessageSentToAllArray = $EmailHeaders->to; //Grab the “TO” header 
    $MessageSentToAllObject = $MessageSentToAllArray[0]; 
    $MessageSentToMailbox = $MessageSentToAllObject->mailbox ."@". $MessageSentToAllObject->host; //Everything before and after the “@” of the recipient 

    $MessageSentFromAllArray = $EmailHeaders->from; //Grab the “FROM” header 
    $MessageSentFromAllObject = $MessageSentFromAllArray[0]; 
    $MessageSentFromMailbox = $MessageSentFromAllObject->mailbox ."@". $MessageSentFromAllObject->host; //Everything before and after the “@” of the sender 
    $MessageSentFromName = $MessageSentFromAllObject->personal; //The name of the person who sent the email 

    $toArray = searchRecipient($MessageSentToMailbox); //Find the correct person to send the email to 
    if($toArray == FALSE) //If the alias they entered doesn’t exist… 
    { 
    $bounceback = 'Sorry the email in your message does not appear to be correct'; 
    /* Send a bounceback email */ 
    $mail = new PHPMailer(); // defaults to using php “mail()” 
    $mail -> ContentType = 'text/plain'; //Plain email 
    $mail -> IsHTML(false); //No HTML 
    $the_body = wordWrap($bounceback, 70); //Word wrap to 70 characters for formatting 
    $from_email_address = '[email protected]'; 
    $mail->AddReplyTo($from_email_address, "domain.Com"); 
    $mail->SetFrom($from_email_address, "domain.Com"); 
    $address = $MessageSentFromMailbox; //Who we’re sending the email to 
    $mail->AddAddress($address, $MessageSentFromName); 
    $mail->Subject = 'Request'; //Subject of the email 
    $mail->Body = $the_body; 
    if(!$mail->Send()) //If the mail fails, send to customError 
     { 
     customError(1, $mail->ErrorInfo, "anon-email.php", "sending the email"); 
     } 
    } 
    else //If the candidate address exists, forward on the email 
    { 
    $mail = new PHPMailer(); // defaults to using php “mail()” 
    $mail -> ContentType = 'text/plain'; //Plain E-mail 
    $mail -> IsHTML(FALSE); //No HTML 
    $the_body = wordwrap($Body, 70); //Wordwrap for proper email formatting 
    $from_email_address = "$MessageSentFromMailbox"; 
    $mail->AddReplyTo($from_email_address); 
    $mail->SetFrom($from_email_address); 
    $address = $toArray[1]; //Who we’re sending the email to 
    $mail->AddAddress($address, $toArray[0]); //The name of the person we’re sending to 
    $mail->Subject = $EmailHeaders->subject; //Subject of the email 
    $mail->Body = ($the_body); 
    if(!$mail->Send()) //If mail fails, go to the custom error 
     { 
     customError(1, $mail->ErrorInfo, "anon-email.php", "sending the email"); 
     } 
    } 
    /* Mark the email for deletion after processing */ 
    imap_delete($connection, $MID); 
    } 
    imap_expunge($connection); // Expunge processes all of the emails marked to be deleted 
    imap_close($connection); 

    function searchRecipient() // function to search the database for the real email 
{ 
    global $MessageSentToMailbox; // bring in the alias email 
    $email_addr = mysql_query("SELECT email FROM tbl WHERE source='$MessageSentToMailbox'"); // temp store of the real email 
    $row = mysql_fetch_array($email_addr); //making temp store of data for use in program 
    if(empty($row['email'])) 
    { 
     return FALSE; 
    } 
    else /* Else, return find the person's name and return both in an array */ 
    { 
     $results = mysql_query("SELECT * FROM tbl WHERE email = '$email_addr'"); // temp store of both queries from this function 
     $row = mysql_fetch_array($results, $email_addr); //making temp store of data for use in program 
     $name = $row['author']; // taking the author data and naming its variable 
     return array($name, $email_addr); // this is the name and the real email address to be used in function call 
    } 
} 

function customError($errno, $errstr, $file, $line) 
{ 
    error_log("Error: [$errno] $errstr in $file at line number: $line",1, "[email protected]","From: [email protected]"); 
    die(); 
} 
+0

아마 어리석은 질문 일지 모르지만 $ 주소가 제대로 채워지고 있는지 확인하십시오. – andrewsi

+0

코드를 살펴본 후 왜 그렇게되지 않았는지 전혀 보지 못했습니다. 뭐 알아 차 렸니? –

+0

오, 그렇지 않으면 반송을 돌려 보내야합니다. –

답변

1

내가 시도 할 것이다 제일 먼저 매개 변수가 전달됩니다. global 키워드를 사용하는 대신 함수 호출에서이를 정의합니다. 또한 mysql_fetch_array는 다음 단계에서 사용하고있는 연관 배열을 다시 전달하지 않는다. 나는 그것을 mysql_fetch_assoc으로 바꿀 것이다 (그것은 본질적으로 같은 것이다). 이 기능에는 몇 가지 다른 작은 구문 수정 기능이 있습니다. 그 기능에 대한 제안 된 변경 사항은 다음과 같습니다. 나는 이것이 당신의 문제를 해결해야한다고 생각합니다. 적어도 앞으로 나아갈 수 있습니다.

function searchRecipient($MessageSentToMailbox) // function to search the database for the real email 
{ 

    $email_addr = mysql_query("SELECT email FROM tbl WHERE source='$MessageSentToMailbox'"); // temp store of the real email 
    $row = mysql_fetch_assoc($email_addr); //making temp store of data for use in program 
    if(empty($row['email'])) 
    { 
     return FALSE; 
    } 
    else /* Else, return find the person's name and return both in an array */ 
    { 
     $email_addr = $row['email']; 
     $results = mysql_query("SELECT * FROM tbl WHERE email = '$email_addr'"); // temp store of both queries from this function 
     $row = mysql_fetch_assoc($results); //making temp store of data for use in program 
     $name = $row['author']; // taking the author data and naming its variable 
     return array($name, $email_addr); // this is the name and the real email address to be used in function call 
    } 
} 

또한 이것을 하나의 쿼리로 결합하여 좀 더 쉽게 만들 수 있습니다. 여기에 그 해결책이 있습니다.

function searchRecipient($MessageSentToMailbox) 
{ 
    $results = mysql_query("SELECT email, author FROM tbl WHERE source='$MessageSentToMailbox'"); 
    $row = mysql_fetch_assoc($results); 
    if(empty($row['email']) || empty($row['author'])) return false; 
    return array($row['email'], $row['author']); 
} 
+0

정말 고마워, 나는 그걸 시도 할 것이다. –

+0

나는 여전히 같은 오류가 발생합니다. –

+0

좋아요, 저는 현재 컴퓨터가 아닌 제 휴대 전화에 있습니다. 따라서 충분한 코드를보기가 어렵습니다. 책상에 가면 나머지 코드를 살펴볼 것입니다. 나는 그것을 보자 마자 나는 그만 쳐다 보았다. –

관련 문제