Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.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,发送电子邮件_Php_Email - Fatal编程技术网

PHP,发送电子邮件

PHP,发送电子邮件,php,email,Php,Email,我可能是完全错误的,但当我尝试运行此代码时,我想向用户发送模板电子邮件,这在我的本地服务器上运行得非常好,但现在上传到我的站点到主机上,它只发送一封空白电子邮件。我留下了我的密码和电子邮件l如果这个代码顺便说一句 <?php function format_email($info, $format){ //set the root $root = $_SERVER['DOCUMENT_ROOT'].'dolearnfinance.com/emai

我可能是完全错误的,但当我尝试运行此代码时,我想向用户发送模板电子邮件,这在我的本地服务器上运行得非常好,但现在上传到我的站点到主机上,它只发送一封空白电子邮件。我留下了我的密码和电子邮件l如果这个代码顺便说一句

<?php

    function format_email($info, $format){

        //set the root
        $root = $_SERVER['DOCUMENT_ROOT'].'dolearnfinance.com/email_templates';

        //grab the template content
        $template = file_get_contents($root.'/signup_template.'.$format);

        //replace all the tags
        $template = preg_replace('({FNAME})', $info['fname'], $template);
        $template = preg_replace('({EMAIL})', $info['email'], $template);
        $template = preg_replace('({KEY})', $info['key'], $template);
        $template = preg_replace('({SITEPATH})','http://www.dolearnfinance.com', $template);

        //return the html of the template
        return $template;
    }

    function send_email($info){

         //format each email
        $body = format_email($info,'html');
        $body_plain_txt = format_email($info,'txt');
        $email = $info['email'];

        //setup the mailer
        // Create the Transport
        $transporter = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
          ->setUsername('*')
          ->setPassword('*')
          ;

        /*
        You could alternatively use a different transport such as Sendmail or Mail:

        // Sendmail
        $transport = Swift_SendmailTransport::newInstance('/usr/sbin/sendmail -bs');

        // Mail
        $transport = Swift_MailTransport::newInstance();
        */

        // Create the Mailer using your created Transport
        $mailer = Swift_Mailer::newInstance($transporter);


        // Create a message
        $message = Swift_Message::newInstance('Verifi Email')
          ->setSubject('Welcome to doLearnFinnace')
          ->setFrom(array('noreply@doLearnFinnace.com' => 'doLearnFinnace'))
          ->setTo(array($email))
          ->setBody($body_plain_txt)
          ;

        // Send the message
        $result = $mailer->send($message);
        return $result;


    }

?>


@Fred ii-如何实施此Fred。谢谢你reply@AmyHyland可能您的主机正在阻止端口或其他脚本。在打开PHP标记之后,将其放在文件顶部的
添加错误报告下,例如
确保模板存在于您认为它在服务器上的位置。是否在
$\u服务器['DOCUMENT\u ROOT'].'dolearnfinance.com/email\u templates'
?@Fred ii-如何实现此Fred。谢谢你reply@AmyHyland可能您的主机正在阻止端口或其他脚本。在打开PHP标记之后,将其放在文件顶部的
添加错误报告下,例如
确保模板存在于您认为它在服务器上的位置。是否在
$\u服务器['DOCUMENT\u ROOT'].'dolearnfinance.com/email\u templates'
上有文件夹?