3

mail() 函数在我的服务器上不起作用。我已经使用基本的 mail() 代码来了解它是否是脚本的问题。仍然没有发送电子邮件。有人建议我更改服务器上的设置以启用 mail() 功能或类似功能。

我怎样才能做到这一点?我怎么知道我的服务器允许 mail() 或它正确运行 mail() ?

有什么建议吗?

4

4 回答 4

0

如果您首先使用共享服务器,我建议您与他们联系,如果他们对此负责。如果它在它可能是您可能导致的事情之前发送电子邮件并且您可能需要更改您的代码。你没有提供任何示例代码,但这是我的,试试吧:

    $to= "$confoemail";
    $subject="Your Contact Request at somewebsite.Com";
    $message= "the message to send";
    $headers  = 'MIME-Version: 1.0' . "\r\n".
     'Content-type: text/html; charset=iso-8859-1' . "\r\n".
     'From: justin@webmasteroutlet.com' . "\r\n" . //that code here //perfectly works, search if the code is built -in of php.
   'Reply-To: justin@webmasteroutlet.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
    mail($to,$subject, $message, $headers);  
于 2013-05-04T05:46:51.787 回答
0

你运行的是什么操作系统?

在 ubuntu 上,您可能会尝试安装邮件服务器(postfix 或 sendmail)。

apt-get install postfix
于 2013-05-04T05:57:16.937 回答
0

如果您使用phpmailer库,则不能使用mail(). 因为它有预定义的功能。您可以通过访问PhpMailer Example Page进行检查。

使用 PhpMailer$mail->Send()代替mail()

PhpMailer 示例代码

require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail             = new PHPMailer();

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

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "yourname@yourdomain"; // SMTP account username
$mail->Password   = "yourpassword";        // SMTP account password

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";

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

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$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!";
}
于 2015-10-06T10:49:34.067 回答
0

在您的主机上进行测试,如果它不起作用,您的主机已禁用邮件。大多数免费服务都会阻止。给我发消息给你一个免费的小型主机测试。

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];;
$subject = $_POST['subject'];
$message = $_POST['message'];
$name = "somename"; $email="test@test.com"; $phone="1111111111" $subject="test"; $message="the message";

$to      = 'info@fullertoncomputerepairwebdesign.com';
$subject = 'Message From Website';
$headers = 'From: info@fullertoncomputerepairwebdesign.com' . "\r\n" .
    'Reply-To: info@fullertoncomputerepairwebdesign.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

$themessage = "Name: ".$name."</br>Email: ".$email."</br>Phone: ".
                $phone."</br>Subject: ".$subject.
                "</br>Message: ".$message;
//echo $themessage;
mail($to, $subject, $themessage, $headers);
于 2016-11-16T06:19:32.020 回答