2010-04-11 6 views
0

J'essaie d'utiliser ce codage, mais il ne traite pas, et il ne génère aucune erreur.Le code d'envoi de courrier PHP ne fonctionne pas

function send_email($subject='Activate Your Account', $html_content, $text_content, $headers) { 

    $en['email'] = '[email protected]'; 
    $to = $en['email']; 
    $en['memb_id'] = '39'; 
    $en['confcode'] = '69696969'; 
    $en['user'] = 'couple'; 

    $text_content = "Confirm Your domain.com Account\r\n"; 
    $text_content.= "UserName: " . $en['user'] . "\r\n"; 
    $text_content.= "Activate Your Account by visiting this link below:\r\n"; 
    $text_content.= "http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "\r\n"; 
    $text_content.= "\r\n"; 
    $text_content.= "______________________\r\n"; 
    $text_content.= "Thanks,\r\n"; 
    $text_content.= "Staff"; 

    $html_content = "<html><body><h1>Confirm Your domain.com Account</h1>"; 
    $html_content.= "<p>UserName: " . $en['user'] . "<br>"; 
    $html_content.= "Activate Your Account by visiting this link below:<br>"; 
    $html_content.= "<a href=http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . ">http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "</a>"; 
    $html_content.= "</p>"; 
    $html_content.= "______________________<br>"; 
    $html_content.= "Thanks,<br>"; 
    $html_content.= " Staff"; 
    $html_content.= "</body></html>"; 

    $mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x'; 

    $headers = "MIME-Version: 1.0\r\n"; 
    $headers.= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n"; 
    $headers.= "Content-Transfer-Encoding: 7bit\r\n"; 

    $body = "This is a multi-part message in mime format.\n\n"; 
    $body.= "--$mime_boundary\n"; 
    $body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n"; 
    $body.= "Content-Transfer-Encoding: 7bit\n\n"; 
    $body.= $text_content; 
    $body.= "\n\n"; 

    $body.= "--$mime_boundary\n"; 
    $body.= "Content-Type: text/html; charset=\"UTF-8\"\n"; 
    $body.= "Content-Transfer-Encoding: 7bit\n\n"; 
    $body.= $html_content; 
    $body.= "\n\n"; 
    $body.= "--$mime_boundary--\n"; 

    $headers.= 'From: <[email protected]>' . "\r\n"; 
    $headers.= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n"; 
    $headers.= 'Date: '.date('n/d/Y g:i A')."\r\n"; 
    $headers.= 'Reply-To: <[email protected]>' . "\r\n"; 

    return mail($to, $subject, $body, $headers); 
    echo $to; 
    echo $subject; 
    echo $body; 
    echo $headers; 
    } 
+2

Etes-vous sûr d'avoir configuré un serveur de messagerie sur votre serveur? sinon, alors c'est le problème. – Ben

+1

Pouvez-vous donner plus de détails sur ce qu'il fait? –

+0

+1 pour les deux. –

Répondre

2

Le dernier bit m'a confondu:

return mail($to, $subject, $body, $headers); 
echo $to; 
echo $subject; 
echo $body; 
echo $headers; 

Vous savez qu'aucun de ces echo déclarations vont se faire exécuter parce qu'ils sont après le return droit?

Essayez d'utiliser error_log pour vérifier les étapes du script ou afficher le journal des erreurs lui-même si vous ne l'avez pas essayé.

+0

mon error_log est activé sur mais pas d'erreurs de sortie – acctman

1

Utilisez PHPMailer/Lite. Sauvez-vous le mal de tête MIME.

require_once('../class.phpmailer.php'); 

$mail    = new PHPMailer(); // defaults to using php "mail()" 

$body    = file_get_contents('contents.html'); 
$body    = eregi_replace("[\]",'',$body); 

$mail->AddReplyTo("[email protected]","First Last"); 

$mail->SetFrom('[email protected]', 'First Last'); 

$mail->AddReplyTo("[email protected]","First Last"); 

$address = "[email protected]"; 
$mail->AddAddress($address, "John Doe"); 

$mail->Subject = "PHPMailer Test Subject via mail(), basic"; 

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 

$mail->MsgHTML($body); 

$mail->AddAttachment("images/phpmailer.gif");  // attachment 
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
1

Ici, je l'ai corrigé pour vous. Je l'ai vérifié et ça marche bien. Assurez-vous également que votre hébergement supporte la fonction mail(). Si SMTP n'est pas activé, vous ne serez pas en mesure d'envoyer du courrier à coup sûr.

CODE RÉVISÉE:

<?php 
function send_email($subject='Activate Your Account') { 

    $en['email'] = '[email protected]'; 
    $to = $en['email']; 
    $en['memb_id'] = '39'; 
    $en['confcode'] = '69696969'; 
    $en['user'] = 'couple'; 

    $text_content = "Confirm Your domain.com Account\r\n"; 
    $text_content.= "UserName: " . $en['user'] . "\r\n"; 
    $text_content.= "Activate Your Account by visiting this link below:\r\n"; 
    $text_content.= "http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "\r\n"; 
    $text_content.= "\r\n"; 
    $text_content.= "______________________\r\n"; 
    $text_content.= "Thanks,\r\n"; 
    $text_content.= "Staff"; 

    $html_content = "<html><body><h1>Confirm Your domain.com Account</h1>"; 
    $html_content.= "<p>UserName: " . $en['user'] . "<br>"; 
    $html_content.= "Activate Your Account by visiting this link below:<br>"; 
    $html_content.= "<a href=http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . ">http://www.domain.com/confirm/" . $en['memb_id'] . "/" . $en['confcode'] . "</a>"; 
    $html_content.= "</p>"; 
    $html_content.= "______________________<br>"; 
    $html_content.= "Thanks,<br>"; 
    $html_content.= " Staff"; 
    $html_content.= "</body></html>"; 

    $mime_boundary = 'Multipart_Boundary_x'.md5(time()).'x'; 

    $headers = "MIME-Version: 1.0\r\n"; 
    $headers.= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\r\n"; 
    $headers.= "Content-Transfer-Encoding: 7bit\r\n"; 

    $body = "This is a multi-part message in mime format.\n\n"; 
    $body.= "--$mime_boundary\n"; 
    $body.= "Content-Type: text/plain; charset=\"charset=us-ascii\"\n"; 
    $body.= "Content-Transfer-Encoding: 7bit\n\n"; 
    $body.= $text_content; 
    $body.= "\n\n"; 

    $body.= "--$mime_boundary\n"; 
    $body.= "Content-Type: text/html; charset=\"UTF-8\"\n"; 
    $body.= "Content-Transfer-Encoding: 7bit\n\n"; 
    $body.= $html_content; 
    $body.= "\n\n"; 
    $body.= "--$mime_boundary--\n"; 

    $headers.= 'From: <[email protected]>' . "\r\n"; 
    $headers.= "X-Sender-IP: $_SERVER[SERVER_ADDR]\r\n"; 
    $headers.= 'Date: '.date('n/d/Y g:i A')."\r\n"; 
    $headers.= 'Reply-To: <[email protected]>' . "\r\n"; 

    return mail($to, $subject, $body, $headers); 

    } 

?> 

espoir qui aide. Laissez nous savoir.

Questions connexes