简体   繁体   English

我正在尝试通过angular发送电子邮件。 我是否以正确的方式处理此问题?

[英]I am trying to send an email via angular. Am I approaching this in the correct manner?

I'm just trying to learn something new. 我只是想学习新东西。 I want to be able to send an email using angular and php. 我希望能够使用angular和php发送电子邮件。 I am turning my form data into an object. 我正在将表单数据变成一个对象。 Then I want to send this object as a variable and send the data to a php file. 然后,我想将此对象作为变量发送,并将数据发送到php文件。 I am able to create the variable but I don't believe the data is being set in the php file. 我能够创建变量,但是我不相信数据是在php文件中设置的。 What am I missing here? 我在这里想念什么?

 angular.module('app', []); var vm = this; var url = '/contact-form-handler.php'; vm.codeStatus = ""; vm.form = {}; vm.submit = function($event) { $event.preventDefault(); console.log(this.form); $http({ method: "POST", url: url, data: vm.form, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }). success(function(result) { console.log(result); console.log('hit'); }). error(function(result) { console.log('error'); }); return false; }; 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <?php header('Access-Control-Allow-Origin: *'); if (isset($_POST["data"])) { $from = 'Portfolio'; $to = 'rafael.heard@gmail.com'; $subject = 'Portfolio Inquiry'; $body = $_POST['data']; mail($to, $subject, $body, $from); $result = 'mail sent'; }else{ $result = 'not set'; } ?> <div ng-app="app" ng-controller="MainController as main"> <form role="form" name="contactForm" ng-submit="main.submit($event)" required novalidate> <div class="form-groups"> <div class="group"> <input type="text" name="username" ng-model="main.form.name" placeholder="Name (required)" required /> </div> <div class="group"> <input type="email" name="userEmail" ng-model="main.form.email" placeholder="Email (required)" required /> </div> <div class="group"> <textarea type="text" name="message" ng-model="main.form.message" ng-minlength="10" rows="10" required></textarea> </div> <button>Send</button> </div> </form> 

I figured this one out. 我想通了。 I change my approach in my php file, and the angular http. 我在我的php文件和尖角http中更改了方法。 I serialized the object. 我序列化了对象。

  var url = 'contact-form-handler.php'; vm.codeStatus = ""; vm.form = {}; vm.submit = function($event) { // $event.preventDefault(); console.log($.param(vm.form)); $http({ method: "POST", url: url, data: $.param(vm.form), headers: {'Content-Type': 'application/x-www-form-urlencoded'} }). success(function(result) { console.log(result); }). error(function(data) { console.log('not sent'); }); return false; }; }]); 
 <?php header('Access-Control-Allow-Origin: *'); if (isset($_POST["subject"])) { $name = $_POST['name']; $subject = $_POST['subject']; $from = $_POST['email']; $message = $_POST['message']; $to = 'rafael.heard@gmail.com'; mail($to, $subject, $message, $from); }else{ echo 'not set'; } ?> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Arraybuffer 无法输入字符串 Angular。 我正在尝试在页面上显示上传的图片 - Arraybuffer is not assinable to type string, Angular. I am trying to show uploaded image on the page 我正在尝试使用 json 参数发送请求 - i am trying to send a request with json parameters 我是否以一种低效的方式使用setTimeout? - Am I using setTimeout in an inefficient manner? 我正在尝试在 angular 中制作打字机效果 - I am trying to make typewriter effect in angular 我正在尝试使用process.env和smtp gmail在meteor中发送电子邮件 - I am trying to send a email in meteor with process.env and smtp gmail 我正在尝试在 email 中将谷歌表格中的范围作为 pdf 发送。 我的脚本卡在 getid() - I am trying to send a range in google sheets as a pdf in an email. My script is getting stuck on getid() 我的Angular控制器功能中未定义“已认证”。 我不确定自己在做什么错。 用尽所有选项。 - “Authenticated” is not defined in my controller function in Angular. I am not sure what I am doing wrong. Running out of all the options. 我正在尝试根据某个类别(mgr,str,wtr)所属的类别发送电子邮件,但它仅发送到该组中的第一封电子邮件? - I am trying to send an email based on which category something falls into (mgr, str, wtr), but it only sends to the first email in the group? 我正在尝试通过 nodemailer 发送电子邮件,我已经允许我的谷歌帐户使用不太安全的应用程序,但仍然出现错误 - i am trying to send email through nodemailer, i have permitted my google account for less secure apps, still getiing error 尝试使用sendgrid发送电子邮件时出错 - I am getting an error when attempting to use sendgrid to send email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM