【问题标题】:sendemail.php is not working [duplicate]sendemail.php 不工作[重复]
【发布时间】:2015-05-01 19:55:46
【问题描述】:

这是我的 sendemail.php。它不工作。上面有没有错误?

<?php
    $name       = @trim(stripslashes($_POST['name'])); 
    $from       = @trim(stripslashes($_POST['email'])); 
    $subject    = @trim(stripslashes($_POST['subject'])); 
    $message    = @trim(stripslashes($_POST['message'])); 
    $to         = 'richardhenokh@gmail.com';//replace with your email

    $headers   = array();
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/plain; charset=iso-8859-1";
    $headers[] = "From: {$name} <{$from}>";
    $headers[] = "Reply-To: <{$from}>";
    $headers[] = "Subject: {$subject}";
    $headers[] = "X-Mailer: PHP/".phpversion();

    mail($to, $subject, $message, $headers);

    die;

【问题讨论】:

    标签: php email send


    【解决方案1】:

    试试这个。它工作正常

    <?php
    $name       = @trim(stripslashes($_POST['name'])); 
    $from       = @trim(stripslashes($_POST['email'])); 
    $subject    = @trim(stripslashes($_POST['subject'])); 
    $message    = @trim(stripslashes($_POST['message'])); 
    $to         = 'imaphpdeveloper@gmail.com';//replace with your email
    
    
    $headers = "MIME-Version: 1.0";
    $headers .= "Content-type: text/plain; charset=iso-8859-1";
    $headers .= "From: {$name} <{$from}>";
    $headers .= "Reply-To: <{$from}>";
    $headers .= "Subject: {$subject}";
    $headers .= "X-Mailer: PHP/".phpversion();
    
    mail($to, $subject, $message, $headers);
    
    die;
    
    ?>
    

    你也可以试试 PHPmailer。 headers 应该是一个字符串而不是一个数组。标题中的 {$from} 等也应正确替换。现在使用上面的代码邮件正在发送。但必须正确替换 {$from}。

    【讨论】:

      猜你喜欢
      • 2017-07-25
      • 2015-04-21
      • 2017-12-12
      • 2012-11-15
      • 2018-03-29
      • 2015-01-20
      • 2014-09-14
      • 1970-01-01
      • 2015-05-26
      相关资源
      最近更新 更多