PHP mailgun邮件问题

时间:2015-11-23 11:11:32

标签: php mailgun mailer

PHP新手并尝试集成mailgun以发送到多个表单。下面是我使用mailgun的PHP脚本的代码。

使用简单的mailgun脚本发送电子邮件时,我可以收到电子邮件,但是当我将其附加到表单时,我不会收到任何电子邮件。

require 'vendor/autoload.php';
use Mailgun\Mailgun;

else if($_GET['method'] == 'send_form'){

    $to = 'myemail@email.com';
    $message = 'Name : '.$_POST['name'].'<br />';
    $message .= 'Mobile : '.$_POST['mobile'].'<br />';
    $message .= 'Email : '.$_POST['email'].'<br />';
    $from = $name.' <'.$from.'>';
    $name = $_POST['name'];

    $subject = 'Email Subj for form 1';

    $headers =  "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: '.$name.' <'.$from.'>' . "\r\n";

    send_mail($to,$from,$subject,$message);
}

else if($_GET['method'] == 'send_form_two'){

    $to = 'myemail@email.com';
    $message = 'Name : '.$_POST['name'].'<br />';
    $message .= 'Mobile : '.$_POST['mobile'].'<br />';
    $message .= 'Email : '.$_POST['email'].'<br />';
    $from = $name.' <'.$from.'>';
    $name = $_POST['name'];

    $subject = 'Email subject for form 2';

    $headers =  "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
    $headers .= 'From: '.$name.' <'.$from.'>' . "\r\n";

    send_mail($to,$from,$subject,$message);


}


function send_mail($to, $from, $subject,$content)
{

    $mgClient = new Mailgun('mailgunkey-here');
    $domain = "mg.domain.com";

    $result = $mgClient->sendMessage($domain, array(
        'from'    => $from,
        'to'      => $to,
        'subject' => $subject,
        'text'    => $content
    ));
}

好像我的代码不想要&#39;来自&#39; =&GT; $从,

将发件人更改为静态电子邮件会导致发送邮件。

0 个答案:

没有答案