2011-04-24 53 views
2
<?php 
    if ($_POST['friends-email']) { 
     $name = "Sender's Name"; 
     $email = "[email protected]"; 
     $recipient = preg_replace("/[^a-z0-9 !?:;,.\/_\[email protected]#$&amp;\*\(\)]/im", "", $_POST['friends-email']); 
     $recipient = preg_replace("/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient); 
     $mail_body = "Default Description"; 
     $subject = "Default Subject"; 
     $header = "From: " . $name . " <" . $email . ">\r\n"; 
     mail($recipient, $subject, $mail_body, $header); 

     echo 'Thank you for recommending <br /> us!'; 

    } else { 
     echo '<form action="" method="post" name="send2friend" id="send2friend"> 
       Friends Email*: 
       <input name="friends-email" id="friends-email" type="text" /> 
       <input type="submit" value="continue" /> 
      </form>'; 
    } 
?> 

不确定为什么这样不起作用,我收到“谢谢你的留言”,但是当我使用自己的电子邮件进行测试时,邮件未送达。告诉朋友表格无法正常工作

+0

尝试使用此邮件的样本邮件(“[email protected]”,“hi”,“tstts”,“stst”)发生了什么? – Efazati 2011-04-24 09:13:56

回答

1

只是说明显而易见的,但你已经把$email = "[email protected]";,你实际上是改变它为一个变量的权利?

您是否打开了所有PHP错误并显示?

error_reporting(E_ALL); 
ini_set('display_errors', '1'); 

使用PHP交互模式(php -a)部署电子邮件

$to  = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n"; mail($to, $subject, $message, $headers); 

然后去here来检查它的接收。这只是为了检查它对您的电子邮件客户端没有问题 - 即它不会阻止电子邮件。

如果您仍然遇到问题,可能与系统的sendmail功能有关。这篇文章在serverfault上提供了很多关于debugging the sendmail function的详细建议。

+0

@Nimbuz到底是什么问题? – 2011-04-24 11:51:10

0

尝试在封闭的邮件传递的if语句

1

你试过用硬编码值的邮件功能,检查phpmail是树立正确的?

然后如果这样,每次替换一个值,你会发现你的bug。我猜这是你正则表达式替换。