mail.php脚本不适用于订阅和联系页面

时间:2017-04-05 10:03:11

标签: php email smtp sendmail google-apps

我的网站开发人员使用此脚本通过我网站上的表单向订阅我的邮件列表的人和与我联系的人发送通知 问题是,收件人无法接收电子邮件,我无法收到有关新订户或联系人的邮件ID通知

发件人ID - notifications@laveshagarwal.com

此外,相同的脚本适用于他的服务器(我们用于测试)但在我的服务器上不起作用

我的SMTP服务器设置有问题吗? 此外,我正在使用Google Apps for Gmail 这是他的剧本

我该怎么办?

<?php
if($_POST['type'] == "subscribe") {

/*$to = "notifications@llaveshagarwal.com";
    $subject = "New Email Subscriber";
    $txt = "Name: ".$_POST['name']."\r\nFrom: ".$_POST['from'];
    $headers = "From: ".$_POST['from'];

    mail($to,$subject,$txt,$headers);

    $to = $_POST['from'];
    $subject = "Thank you for subscribing with us.";
    $txt = "Hey ".$_POST['name']." ,\r\nGreetings from LLavesh Agarwal Textile Agency\r\nThank you for subscribing with us for Exclusive and Latest Catalogs and product launches.\r\nWe will update you soon.\r\n\r\nRegards,\r\nTeam LLavesh Agarwal\r\n\r\n*This is an automated Email. Please do not reply to this Email id. If you wish to talk to us, kindly Email us at hello@llaveshagarwal.com";
    $headers = "From: notifications@llaveshagarwal.com";

    mail($to,$subject,$txt,$headers);*/

    $link = mysql_connect('localhost', 'llavesha_admin', 'Admin@1234');
    $db= mysql_select_db('llavesha_contact_system', $link);

    $insert='insert into subscribe (name,email) values ("'.$_POST["name"].'","'.$_POST["from"].'")';
    if(mysql_query($insert)) {
        echo "success";
    } else {
        echo "fail";
    }
}

elseif($_POST['type'] == "contact") {
    $to = "notifications@llaveshagarwal.com";
    $subject = "New Contact";
    $txt = "Name: ".$_POST['name']."\r\nContact: ".$_POST['mobile']."\r\nCategory: ".$_POST['bussiness_type']."\r\nDescription: ".$_POST['project_detail'];
    $headers = "From: ".$_POST['from'];

    mail($to,$subject,$txt,$headers);

    $to = $_POST['from'];
    $subject = "Thank you for contacting us.";
    $txt = "Hey ".$_POST['name']." ,\r\nGreetings from LLavesh Agarwal Textile Agency\r\nThank you for contacting us.\r\nWe will update you soon !\r\n\r\nRegards,\r\nTeam LLavesh Agarwal\r\n\r\n*This is an automated Email. Please do not reply to this Email id. If you wish to talk to us, kindly Email us at hello@llaveshagarwal.com";
    $headers = "From: notifications@llaveshagarwal.com";

    mail($to,$subject,$txt,$headers);

    echo "success";
}

&GT;

1 个答案:

答案 0 :(得分:0)

你在Windows(wamp)上工作吗?你有没有在php.ini上启用php sendmail?阅读:http://us3.php.net/manual/en/function.mail.php

或者您可以阅读:php mail() function on localhost

如果您想使其更简单,请使用phpmailer:https://github.com/PHPMailer/PHPMailer

如何使用@pooria:How to configure PHP to send e-mail?

require('./PHPMailer/class.phpmailer.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';

$body = 'This is the message';

$mail->IsSMTP();
$mail->Host       = 'smtp.gmail.com';

$mail->SMTPSecure = 'tls';
$mail->Port       = 587;
$mail->SMTPDebug  = 1;
$mail->SMTPAuth   = true;

$mail->Username   = 'me.sender@gmail.com';
$mail->Password   = '123!@#';

$mail->SetFrom('me.sender@gmail.com', $name);
$mail->AddReplyTo('no-reply@mycomp.com','no-reply');
$mail->Subject    = 'subject';
$mail->MsgHTML($body);

$mail->AddAddress('abc1@gmail.com', 'title1');
$mail->AddAddress('abc2@gmail.com', 'title2'); /* ... */

$mail->AddAttachment($fileName);
$mail->send();