使用PHPMailer和ionic 3发送电子邮件 [英] send Email with PHPMailer and ionic 3

查看:75
本文介绍了使用PHPMailer和ionic 3发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个应用程序,该应用程序中要发送的任务之一就是向用户发送电子邮件,

I'm building an application and one of the tasks in this app is sending is emails to the users,

这是我的php代码

<?php
require_once __DIR__ . '/connect.php';
require 'phpmailer/PHPMailerAutoload.php';

$response = array();
 $_POST['fristName']=" null";
 $_POST['lastName']=" null";
$_POST['email']=" null";
$_POST['phoneNumber']=" null";
 if($_POST['fristName']&&$_POST['email']&&$_POST['phoneNumber']){
 	
 	
$mail = new PHPMailer;
$mail->setFrom($_POST['email'], $_POST['fristName'].' '.$_POST['lastName']." - Application mobile");
$mail->addAddress('exemple.xx@xxxxx.com', 'Mobile Android');
$mail->Subject  = 'Email from : '.$_POST['email'];
 
            $message = utf8_encode(htmlentities("hi dear", ENT_QUOTES, "UTF-8"));


            $message .="<p>".utf8_encode(htmlentities($_POST['fristName'], ENT_QUOTES, "UTF-8"))."</p>"
			$message .="<p>".utf8_encode(htmlentities($_POST['lastName'], ENT_QUOTES, "UTF-8"))."</p>"
			$message .="<p>".utf8_encode(htmlentities($_POST['email'], ENT_QUOTES, "UTF-8"))."</p>"
			$message .="<p>".utf8_encode(htmlentities($_POST['phoneNumber'], ENT_QUOTES, "UTF-8"))."</p>"
            

            $message .="<br/><br/>Cordialement,";

$mail->Body  = $message;
$mail->IsHTML(true); 
if(!$mail->send()) {

   $response["success"] = 0;
    $response["message"] = "Email not sent";
} else {
    $response["success"] = 1;
    $response["message"] = "succes";
}

}

这是我的页面联系人.

sendEmail(){

      var headers = new Headers();
    headers.append("Accept", 'application/json');
    headers.append('Content-Type', 'application/json' );
    const requestOptions = new RequestOptions({ headers: headers });

    let postData = {
        fristName: this.fristName,
        lastName: this.lastName,
        email:this.Email,
        phoneNumber:this.phoneNumber,
    }

    this.http.post("http://www.android.transatour.ma/contact_script.php",postData, requestOptions)
      .subscribe(data => {
        console.log(data['_body']);
       }, error => {
        console.log(error);
      });

      //console.log(this.fristName+" "+this.lastName+" "+this.Email+" "+this.phoneNumber);  
  }

我成功发送了电子邮件,但全部 场什么都不给我

i had success to send the email but all field give me nothing

我不知道我在做什么错

这是一个更好理解的图像

推荐答案

您的PHP脚本是否从Ionic应用程序接收数据,我认为您的发布请求未随PHP脚本的请求一起发送任何数据?您需要像这样添加您的Ionic应用程序数据

Is your PHP script receive Data from the Ionic application, I think your post request is not sent any data along with the request your PHP script Accept form-data so you need to add your Ionic application data like this

 send(){
    var headers = new Headers();
    headers.append("Accept", "application/json");
    let options = new RequestOptions({ headers: headers });

    let body = new FormData();
    body.set("fristName",this.fristName);
    body.set('lastName', this.lastName);
    body.set("phoneNumber", this.phoneNumber);
    body.set("email", this.email);
    return this.http
      .post("http://www.android.transatour.ma/contact_script.php", body, options)
      .map(res => res.json());
}

尝试一下.

这篇关于使用PHPMailer和ionic 3发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆