如何使用angularjs和PHP脚本从网站发送电子邮件? [英] How do I send an email from website with angularjs and PHP script?

查看:88
本文介绍了如何使用angularjs和PHP脚本从网站发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个联系表单,以便用户可以直接从网站发送电子邮件到我的电子邮件地址。我遇到的问题是,无论我使用什么脚本或指南,它都不起作用。



我希望有人可以看一看并告诉我我做错了什么在这里。



我尝试了什么:



现在我清理了我的代码,以便更容易看到是否有错误,所以我没有任何东西来验证输入文本。



我现在拥有的是我的3个文件服务器是contact.php,contact.html和app.js,我在同一台服务器上创建了一个电子邮件帐户,因为它是我托管时的一部分。



我的HTML代码:

I want to create a contact form so that users can send emails directly from the website to my email address. The problem iam having is that it doesn't work no matter what script or guide i used.

I hope someone can take a look and tell me what iam doing wrong here.

What I have tried:

Now i cleaned my code so that it is easier to see if something is wrong so i don't have anything to validate the input text.

what i currently have are 3 files in my server which are contact.php, contact.html and app.js and i created an email account on the same server because it is part of the package when i hosted it.

My html code:

<div class=" container formcontainer">
        
      <form method="post">
            
            <input type="text" name="subject" class="form-control" placeholder="Subject..." ng-model="formData.subject">
            
            <input type="email" name="email" class="form-control" placeholder="Your email..." ng-model="formData.email">
         
            <textarea  rows="5" cols="50" class="form-control" placeholder="You message" ng-model="formData.message"></textarea>
           
            <button type="submit" ng-click="processForm()" class="btn btn-success btn-lg btn-block">Submit!</button>
      </form>
   </div>





我的控制器:



My controller:

app.controller("contactController", ['$scope', '$http', function ($scope, $http) {


        $scope.formData = {

            subject: '',
            email: '',
            message: ''
        };
        console.log(formData);
        // process the form
        $scope.processForm = function () {
            $http({
                method: 'POST',
                url: 'contact.php',
                data: $scope.formData,
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            })


        };


    } ]);





我的PHP脚本:



My php script:

<?php


$post_data = file_get_contents("php://input");
$data = json_decode($post_data);



//email information
$to = "lurtze@hotmail.com";

$subject = $data['subject'];
$userEmail=$data['email'];
$message=$data['message'];



$headers = 'From: ' . $userEmail . "\r\n" .
        'Reply-To:'.$userEmail . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

//php mail function to send email on your email address
mail($to, $subject, $message, $headers);

//Email response
  echo "Thank you for contacting us!";
  }

?>

推荐答案

scope','
scope', '


http', function


scope,


这篇关于如何使用angularjs和PHP脚本从网站发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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