-1

如何使用邮件功能配置 smtp 设置 smtp 是必需的,因为由于安全原因,Web 托管不允许在没有 smtp 设置的情况下发送电子邮件。

warning error: mail() has been disabled for security reasons

现在如何使用此邮件功能()配置 smtp 设置?

<?php 
if(isset($_REQUEST['confirm'])){
$your_email = 'non-reply@test.com'; //CHANGE TO YOUR SETTINGS
$domain = $_SERVER["HTTP_HOST"]; //YOUR DOMAIN AND EXTENSION
$to = $email;
$subject = 'Demo Your Order';
$message = 'test1234';
$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  
$headers .= "From: Demo.Pk<'.$your_email.'@'.$domain.'>\r\n" .  
//"Reply-To: $from \r\n" .  
"X-Mailer: PHP/" . phpversion(); 

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

?>

4

1 回答 1

2

似乎邮件已禁用或在您的 PHP.ini 中没有正确设置。我认为,您仍然可以使用 SMTP 设置将电子邮件发送到 gmail 等其他 SMTP 服务器。请检查以下代码,它可能会帮助您解决此问题。下面的代码是使用 Mail.php frm PEAR

<?php

       require_once "Mail.php";

        $from = "<me@gmail.com>";
        $to = "<you@gmail.com>";
        $subject = "Hi!";
        $body = "Hi,\n\nHope this helps?";

        $host = "ssl://smtp.gmail.com";
        $port = "465";
        $username = "me@gmail.com";  //<> give errors
        $password = "mypassword";

        $headers = array ('From' => $from,
          'To' => $to,
          'Subject' => $subject);
        $smtp = Mail::factory('smtp',
          array ('host' => $host,
            'port' => $port,
            'auth' => true,
            'username' => $username,
            'password' => $password));

        $mail = $smtp->send($to, $headers, $body);

        if (PEAR::isError($mail)) {
          echo("<p>" . $mail->getMessage() . "</p>");
         } else {
          echo("<p>Message successfully sent!</p>");
         }

    ?>

您还可以使用其他一些邮件库,如 PHPMailer

于 2013-04-04T13:56:43.653 回答