I have been trying to post HTML data from Angular to PHP mailer as json 
object and decoding them on PHP. However I can only send h1, h2.... p 
elements, when I use div / a etc as an object, it show two errors. Anonymous 
function on posting and No 'Access-Control-Allow-Origin' header is present 
on the requested resource. Origin 'http://127.0.0.1:57948' is therefore not 
allowed access. PHP file is on t remote server.

Her is my code

Angular-

$scope.documentContents = "<h2><a href='/index.html'> Div Contents with a tag 
</a><h2>"; // this gives error
// $scope.documentContents = "<h2> Div Contents with a tag <h2>"; this one 
works fine

$scope.sendEmailWithInfo = function(){
    console.log('clicked');
    $scope.dataToSend = {
        person: $scope.Fullname,
        contents: $scope.documentContents            
    };

    console.log($scope.dataToSend.contents);

    userServices.sendEmail($scope.dataToSend).success(function(response){
        console.log(response);
    })
};


Service

sendEmail: function (dataToSend) {

        return $http.post('http://....remote.php', dataToSend, {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        });
    }


PHP


<?php
header('Access-Control-Allow-Origin: *');require 
'PHPMailer-master/PHPMailerAutoload.php';


$postdata = file_get_contents("php://input");
$request = json_decode($postdata);@$person = $request->person; //used in 
template@$contents = $request->contents;



$otherContents = "<h2>This is h2 html content</h2>";
$otherPerson= "Other Person";



$mail = new PHPMailer;

$mail->isSMTP();            
                         
$mail->Host = "smtp.gmail.com";

$mail->SMTPAuth = true;                          
     
$mail->Username = "[email protected]";                 
$mail->Password = "password";                           

$mail->SMTPSecure = "tls";                           

$mail->Port = 587;


ob_start();require("template.php");
$html = ob_get_contents();
ob_end_clean();





$mail->setFrom('email here', $person);

$mail->addReplyTo('email here', 'First Last');

$mail->addAddress('email', 'John Doe');

$mail->Subject = 'PHPMailer sendmail test';

$mail->msgHTML($html);


$mail->AltBody = 'This is a plain-text message body';
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;} else {
    echo "Message sent!";}?>






-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to