【问题标题】:send mail using php using xampp使用 php 使用 xampp 发送邮件
【发布时间】:2014-07-27 07:01:57
【问题描述】:

我无法发送邮件,有人可以帮忙吗?我尝试在 google 上冲浪,但仍然没有答案。 我正在使用名为 XAMPP 的应用程序,这可能是它的原因吗? XAMPP 是否具备所有 php 功能?

这是mailform.php

<?php 
$to = "ratisharabidze@gmail.com"; 
$subject = "Test mail"; 
$message = "Hello! This is a simple email message."; 
$from = "ratisharabidze@yahoo.com"; 
$headers = "From: $from"; 
mail($to,$subject,$message,$headers); 
echo "Mail Sent."; 
?>

这是一个form.html

<html> 
<body> 
<?php 
function spamcheck($field) 
{ 
    //eregi() performs a case insensitive regular expression match 
    if(eregi("to:",$field) || eregi("cc:",$field)) 
    { 
        return TRUE; 
    } else 
    { 
        return FALSE; 
    } 
} //if "email" is filled out, send email 

if (isset($_REQUEST['email'])) 
{ 
    //check if the email address is invalid 
    $mailcheck = spamcheck($_REQUEST['email']); 
    if ($mailcheck==TRUE) 
    { 
        echo "Invalid input";
    } 
    else 
    { 
        //send email 
        $email = $_REQUEST['email'] ; 
        $subject = $_REQUEST['subject'] ; 
        $message = $_REQUEST['message'] ; 
        mail("someone@example.com", "Subject: $subject", $message, "From: $email" ); 
        echo "Thank you for using our mail form"; 
    } 
} 
else 
//if "email" is not filled out, display the form 
{ 
    echo "<form method='post' action='mailform.php'> 
    Email: <input name='email' type='text' /><br /> 
    Subject: <input name='subject' type='text' /><br /> 
    Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> 
    <input type='submit' /> 
    </form>";
?> 

</body> 
</html>

【问题讨论】:

  • 你在你的 xampp 上打开 apache 了吗?

标签: php email xampp


【解决方案1】:

看看PHPMailer;比 PHP Mail() 函数好多了:)

【讨论】:

  • 谢谢!我曾经是构建 PHPMailer 团队的一员! :)
【解决方案2】:

由于您是新手,最简单的方法是使用免费的gmail SMTP server

XAMPP 中编辑您的php.ini(在控制面板中,单击apache 旁边的config 按钮并选择php.ini)。

在该文件中找到下面的行。通过从行首删除 semi-colon 来取消注释 sendmail_path

;sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

接下来为 gmail 配置您的 sendmail settings

smtp_server 应该是 mail.gmail.com.auth_usernameauth_password 将是您的 gmail 用户名和密码。 smtp_port 应该是 465。

重新启动 XAMPP,如果一切正常,您应该一切顺利。

【讨论】:

  • 我必须做什么?我是 php 新手
猜你喜欢
  • 2015-12-16
  • 2013-04-06
  • 2015-01-05
  • 2015-07-03
  • 2014-07-29
  • 1970-01-01
  • 2012-12-15
  • 2015-06-01
相关资源
最近更新 更多