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_Mailer - Fatal编程技术网

PHP确认电子邮件

PHP确认电子邮件,php,email,mailer,Php,Email,Mailer,我在我的网站上有一个注册表格,完成后详细信息存储在CSV文件中,但我还想向用户发送一封确认电子邮件。问题是电子邮件到达时是空白的,我所做的是创建了一个template.php文件,其中包含我要发送的电子邮件结构,在这个模板结构中,我有来自其他文件的函数来确定注册日期。template.php中的模板包装在一个函数中,我将该函数作为mail()atrebiutes的一部分从\u调用到\u csv.php: 希望这是有意义的,你们理解我,看看代码: template.php: <?php

我在我的网站上有一个注册表格,完成后详细信息存储在CSV文件中,但我还想向用户发送一封确认电子邮件。问题是电子邮件到达时是空白的,我所做的是创建了一个
template.php
文件,其中包含我要发送的电子邮件结构,在这个模板结构中,我有来自其他文件的函数来确定注册日期。
template.php
中的模板包装在一个函数中,我将该函数作为mail()atrebiutes的一部分从\u调用到\u csv.php:

希望这是有意义的,你们理解我,看看代码:

template.php

   <?php

function getMailContent(){

$subject = "OPES Academy- Workshop confirmation";
$message = "
<body style='background-color: #eeeeee; margin: 0 auto; font-family: 'lato',sans-serif'>

<table style='background-color:#ffffff' width='600' heigth='auto' cellspacing='0' cellpadding='0' align='center'>
    <tr>
        <td>
            <table width='600' style='background-color: #5e8ab5;' align='center' cellpading='0' cellspacing='0'>
                <tr>
                    <td>
                        <p style='padding-left: 20px;'><img src='http://opesacademy.com/emails/images/logo.png'
                                                            width='100' alt='Opes Academy'></p>
                    </td>
                    <td style='text-align: right; padding-right: 10px; color: #ffffff'>
                        KNOWLEDGE | WEALTH | POWER
                    </td>
                </tr>
            </table>
        </td>
    </tr>

    <tr>
        <td style='padding: 10px;'>

            <h1 class='skinytxt text-center txtblue'>Thank you for reserving your place</h1>

                    <p>&nbsp;</p>

                    <p class='txt-white text-center'>Thanks for your registration, we will be looking forward to see you at the";

                     ?>
                     <?php
                        require('helper.php');
                        echo ConvertDate( $_SESSION['date'] );
                    ?>
                    <?php
 $message.="
                    <p align='center'>Address: 6 Thomas More Square, London, E1W 1XZ</p>

                    </p>

                    <p class='txt-white text-center'>If you have any more questions we will be glad to help you, just call us on 020 3675 9000 or email us on
                        support@opesacademy.com</p>

        </td>
    </tr>

</table>

<table width='600' style='background-color: #5e8ab5;' align='center' cellpading='0' cellspacing='0'>
    <tr>
        <td>
            <p style='padding-left: 10px; padding-right: 10px; font-size: 10px'>Trading and investing often
                involves a very high degree of risk. Past results are
                not indicative of future returns and financial instruments can go down as well as up
                resulting
                in you receiving less than you invested. Do not assume that any recommendations, insights,
                charts, theories, or philosophies will ensure profitable investment. Spread betting, trading
                binary options and CFD's carry a high risk to your capital, can be very volatile and prices
                may
                move rapidly against you. Only speculate with money you can afford to lose as you may lose
                more
                than your original deposit and be required to make further payments. Spread betting may not
                be
                suitable for all customers, so ensure you fully understand the risks involved and seek
                independent advice if necessary</p>
        </td>
    </tr>
</table>

</body>";

$headers = "Content-type: text/html\r\n";

return compact($subject, $message, $headers);
}
?>

$to
变量包含用户输入到表单中的电子邮件。…

您的mail方法不会返回任何内容。 请添加压缩(“标题”、“消息”、“主题”)

然后在其他函数中使用返回的数组

<?php
// you might place the following method into mail.php

// formerly your mail function, renamed to avoid function name clash
// with PHP's own function mail
function getMailContent(){
   $subject = "OPES Academy- Workshop confirmation";
   $message = "Message";
   $headers = "Content-type: text/html\r\n";

   // return the things :)
   return compact('subject', 'message', 'headers');
}

// Usage:

// from_to_csv.php

// you need to include the file mail.php, 
// if you want to access the function  getMailContent()
// uncomment this line, if you split the PHP code into the files.
// include 'mail.php';    

// fetch mail content as array
$mailContent = getMailContent();

// access array values
mail($to, 
     $mailContent['subject'], $mailContent['message'], 
     $mailContent['headers'],
     "-f info@opesacademy.com"
);
?>
无法在本地函数之外访问本地变量(在本例中为$message和$header)。这称为“变量范围”,您应该对其进行更多的阅读(此处:)

在本例中,$message和$header在本地作用域中声明:function mail(),当您调用PHP mail函数时,您试图在全局作用域中访问它们

<?php
// you might place the following method into mail.php

// formerly your mail function, renamed to avoid function name clash
// with PHP's own function mail
function getMailContent(){
   $subject = "OPES Academy- Workshop confirmation";
   $message = "Message";
   $headers = "Content-type: text/html\r\n";

   // return the things :)
   return compact('subject', 'message', 'headers');
}

// Usage:

// from_to_csv.php

// you need to include the file mail.php, 
// if you want to access the function  getMailContent()
// uncomment this line, if you split the PHP code into the files.
// include 'mail.php';    

// fetch mail content as array
$mailContent = getMailContent();

// access array values
mail($to, 
     $mailContent['subject'], $mailContent['message'], 
     $mailContent['headers'],
     "-f info@opesacademy.com"
);
?>

您必须将其从函数中传回,才能以_to_csv.php文件的形式访问它们。

看起来您正试图从Mail()函数中访问$subject、$message和$headers变量,除非先返回它们,否则将无法访问这些变量。。。在模板PHP中尝试以下操作:

function MyMail() {
   // Your variables and content here


   return Array(
    "subject" => $subject,
    "message" => $message,
    "headers" => $headers;
   );
}
在主文件中:

$to = $data['email'];

require('template.php');
$content = MyMail();

//csv
if(@$_POST['land']=='fw'){
    $path=='/home/content/CSV/';
    $fName=$path.'free_workshop-'.date( "F_j_Y" ).".csv";
     mail($to, $content["subject"], $content["message"], $content["headers"],"-f info@opesacademy.com");

}

一个超级简单的修复方法是将template.php变成一个函数

<?php
// you might place the following method into mail.php

// formerly your mail function, renamed to avoid function name clash
// with PHP's own function mail
function getMailContent(){
   $subject = "OPES Academy- Workshop confirmation";
   $message = "Message";
   $headers = "Content-type: text/html\r\n";

   // return the things :)
   return compact('subject', 'message', 'headers');
}

// Usage:

// from_to_csv.php

// you need to include the file mail.php, 
// if you want to access the function  getMailContent()
// uncomment this line, if you split the PHP code into the files.
// include 'mail.php';    

// fetch mail content as array
$mailContent = getMailContent();

// access array values
mail($to, 
     $mailContent['subject'], $mailContent['message'], 
     $mailContent['headers'],
     "-f info@opesacademy.com"
);
?>
删除该行

function mail(){
然后是结尾的花括号

}
你的脚本会运行得很好


查看更多信息

您是否尝试在浏览器窗口中打印
template.php
的输出?在我看来,您已经用自己的
mail()
函数重新声明了PHPs
mail()
函数。这不应该引发一个关于尝试重新声明
邮件的错误吗?
?不会引发任何错误,只会引发我为空的电子邮件,但如果我将电子邮件模板代码复制并通过表单_to _csv。php it Works我应该在template.php上的哪里添加compact(),比如:$send=compact($header,$message,$subject)和形式为_to_csv mail($to,$send)…?我添加了一个小示例来演示它。我已经按照您的指示进行了一些操作,请检查我问题中的编辑,我收到了这个错误消息:我们期待很快看到您警告:无法修改标题信息-标题已经由/home/content/24/12131124/html/php/template.php:36)在/home/content/24/12131124/html/php/form_to_csv.php第201行发送(输出开始于/home/content/24/12131124/html/php/template.php:36),不确定此错误来自何处。如果您注释掉include语句并将其包装在PHP标记中,那么我发布的示例应该是开箱即用的。。。?因此函数myMail(){}'function myMail(){$message=“HELLO USER

”}'是的,本质上更改函数名,使其不会冲突,只将返回数组放在底部