Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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
使用phpmailer&x2B发送邮件;ajax(已包含一个php文件)_Php_Jquery_Ajax - Fatal编程技术网

使用phpmailer&x2B发送邮件;ajax(已包含一个php文件)

使用phpmailer&x2B发送邮件;ajax(已包含一个php文件),php,jquery,ajax,Php,Jquery,Ajax,我将要实现我的第一个ajax函数,但在此之前我有一个问题找不到答案 我网站上的联系人表单在每个页面上都可以访问(在网站的页脚中),我想使用ajax触发phpmailer,这样页面就不需要刷新,导航也不会中断 在我的页面顶部,我包含了我的函数库: <?php require_once('functions.php'); $app = new action(); $app->init(); ?> <!DOCTYPE html> <htm

我将要实现我的第一个ajax函数,但在此之前我有一个问题找不到答案

我网站上的联系人表单在每个页面上都可以访问(在网站的页脚中),我想使用ajax触发phpmailer,这样页面就不需要刷新,导航也不会中断

在我的页面顶部,我包含了我的函数库:

<?php
    require_once('functions.php');

    $app = new action();
    $app->init();
?>

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
</body>
</html>
据我所知,要使用ajax和phpmailer发送邮件,我需要使用JQuery处理输入信息,然后使用ajax将数据发送到包含phpmailer函数的php文件

我的问题是:我是否可以将信息发送到我的
functions.php
文件,而不是这个ajax函数的专用文件?是否可能(即使它包含在我的页面中)?
这是一个好主意还是有任何缺点(如果可能的话)

我想知道这一点,因为我看不出有必要为我的页面中已经包含的函数创建一个新的php文件


抱歉,如果标题/解释看起来很草率,我缺少一些ajax词汇。

如果您想使用jquery/ajax并尽可能利用现有的sendMail函数,您只需要确保函数能够处理来自新创建的ajax调用的post请求。没有必要创建一个全新的php文件。谢谢,所以,我在一个已经包含在我的页面中的文件中使用的函数不会有问题吧?(我现有的邮件函数位于
functions.php
中,我在每个页面中都包含了该函数。您只需在函数文件(或ajax调用中要调用的任何文件)中添加一些内容,即可识别post请求并调用sendMail函数。
public static function sendMail($mail, $name, $subject, $body) {
 // stuff to send the mail with phpmailer
}