sendmail_from中没有值;如何在PHP中配置?

时间:2014-07-14 15:39:11

标签: php email sendmail

我添加了以下内容并得到了错误:

<?php
    error_reporting(E_ALL|E_STRICT);
    ini_set('display_errors', 1);
    echo 'I am : ' . `whoami`;
    $result = mail('anguyen@student.lasalle.edu','Testing 1 2 3','This is a test.');
    echo '<hr>Result was: ' . ( $result === FALSE ? 'FALSE' : 'TRUE') . $result;
    echo '<hr>';
    echo phpinfo();
?>

我从类似的帖子中获得了此代码 - &gt; Mail returns false。所以我从结果页面中找到了问题所在:

enter image description here

我有两个问题,我的sendmail_path是否正确?我知道sendmail_from显然是错误的,因为没有设置值...那么我该如何设置sendmail_from?

提前致谢。

1 个答案:

答案 0 :(得分:0)

使用此:

<?php
$owner_email = "user1@yousite.com, user2@yousite.ru, user3@yousite.ru";
$headers = 'From: support@yousite.com' . "\r\n" . 'Reply-To: support@yousite.com' . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
//  $headers = 'From:' . $_POST["email"] . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$subject = 'message from you site, sender name  ' . $_POST["name"];
$messageBody = "";

if($_POST['name']!='nope'){
    $messageBody .= '<p>Name: ' . $_POST["name"] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
    $messageBody .= '<p>Email: ' . $_POST['email'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}else{
    $headers = '';
}
if($_POST['state']!='nope'){
    $messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='nope'){
    $messageBody .= '<p>Phone: ' . $_POST['phone'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['fax']!='nope'){
    $messageBody .= '<p>Fax: ' . $_POST['fax'] . '</p>' . "\n";
    $messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
    $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}

if($_POST["stripHTML"] == 'true'){
    $messageBody = strip_tags($messageBody);
}

try{
    if(!mail($owner_email, $subject, $messageBody, $headers)){
        throw new Exception('mail failed');
    }else{
        echo 'mail sent';
    }
}catch(Exception $e){
    echo $e->getMessage() ."\n";
}
?>