Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 邮件()函数ini\u set()smtp服务器本地主机不工作 电子邮件: 主题: 消息:_Php_Html_Smtp - Fatal编程技术网

Php 邮件()函数ini\u set()smtp服务器本地主机不工作 电子邮件: 主题: 消息:

Php 邮件()函数ini\u set()smtp服务器本地主机不工作 电子邮件: 主题: 消息:,php,html,smtp,Php,Html,Smtp,错误 mail():无法在“localhost”端口25连接到mailserver,请验证php.ini中的“SMTP”和“SMTP_端口”设置或使用ini_集()** 试试这个,它对你有用 <?php if (isset($_REQUEST['email'])) { $admin_email = "example@gmail.com"; $email = $_REQUEST['email']; $subject = $_REQUEST['subject'];

错误

mail():无法在“localhost”端口25连接到mailserver,请验证php.ini中的“SMTP”和“SMTP_端口”设置或使用ini_集()**


试试这个,它对你有用

 <?php

  if (isset($_REQUEST['email']))  {


  $admin_email = "example@gmail.com";
  $email = $_REQUEST['email'];
  $subject = $_REQUEST['subject'];
   $comment = $_REQUEST['comment'];


   ini_set("SMTP","localhost");
   ini_set("smtp_port","25");
   ini_set("sendmail_from",$email);

   mail($admin_email, "$subject", $comment, "From:" . $email);
    echo "Thank you for contacting us!";
   }


   else  {
  ?>

  <form method="post">
   Email: <input name="email" type="text" /><br />
   Subject: <input name="subject" type="text" /><br />
   Message:<br />
  <textarea name="comment" rows="15" cols="40"></textarea><br />
  <input type="submit" value="Submit" />
  </form>

  <?php
  }
 ?>

您的机器上运行邮件服务器吗?使用phpmailer for smtp我的机器上没有任何邮件服务器您刚才解释了为什么它不工作。Thx@jiri hrazdil!如果您想使用smtp,那么没有phpmailer是可能的,因此您需要使用phpmailer
<?php
include "PHPMailer_5.2.4/class.phpmailer.php";

  if (isset($_REQUEST['smtp']))  {
    $email=$_POST['email'];
$mail        = new PHPMailer();

$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; 
$mail->IsHTML(true);
$mail->Username = "userid@gmail.com";
$mail->Password = "password";
    $mail->AddAddress($email, 'ashu');
    $mail->Subject = "SMTP Receivced";
    $mail->Body    = "<b>Succesfully SMTP Receivced</b>";
    $text = 'Text version of email';
    $html = '<html><body>HTML version of email</body></html>';
    $file = 'index.php';
    $crlf = "\n";
    $hdrs = array(
        'email' => 'example@gmail.com',
        'Subject' => 'Test subject message',
        'comment' => 'Test comment',
    );
    if ($mail->send($hdrs))
    //if (mail($subject,$message, $headers))
        {
        echo "<script> alert('Thank you for contacting us!');window.location = '';</script>";
    } else {
        echo "Mailed Error: " . $mail->ErrorInfo;
    }

  }
  ?>

  <form method="post">
   Email: <input name="email" type="text" /><br />
   Subject: <input name="subject" type="text" /><br />
   Message:<br />
  <textarea name="comment" rows="15" cols="40"></textarea><br />
  <input type="submit" name="smtp" value="Submit" />
  </form>