我在角度为$scope
的联系页面中使用PHPMailer。我收到了电子邮件,但我没有在联系页面中收到任何消息。
联系页面表格:
<form role="form" ng-submit="sendContact()" name="contactform" id="contactform" action="" method="post">
<fieldset>
<div>
<label for="name" accesskey="U" ng-bind-html="contact.hname"></label>
<input type="text" name="contactName" id="contactName" required ng-model="contactName" />
</div>
<div>
<label for="email" accesskey="E" ng-bind-html="contact.hemail">
<span>*</span>
</label>
<input required id="contactEmail" name="contactEmail" type="email" ng-model="contactEmail" pattern="^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$" />
</div>
<div>
<label for="comments" accesskey="C" ng-bind-html="contact.hmessage">
<span>*</span>
</label>
<textarea required id="contactText" name="contactText" cols="40" rows="3" spellcheck="true" ng-model="contactMessage" ></textarea>
</div>
</fieldset>
<input type="submit" class="submit" id="submit" ng-bind-html="contact.send" ng-disabled="submitButtonDisabled" />
<div class="clearfix"></div>
<p ng-class="contact.result" style="padding: 15px; margin: 0;" ng-bind-html="contact.sendContactResult"></p>
<span style="color: green;" ng-bind-html="contact.sendContactResult"></span>
<p ng-show='contact.send' style="padding: 15px; margin: 0;"></p>
</form>
控制器
$scope.sendContact = function(){
$http({
method: 'POST',
url: 'admin/api/mailer/contact.php',
data: {
name: $scope.contactName,
email: $scope.contactEmail,
message: $scope.contactMessage,
}, //param method from jQuery
headers : {
'Content-Type': 'application/x-www-form-urlencoded'
} //set the headers so angular passing info as form data (not request payload)
}).success(function(r) {
toastr.success("Eposta adresiniz sistemimize başarıyla kaydedildi.");
console.log(data);
$scope.contact.sendContactResult = $sce.trustAsHtml("Mesajınız başarıyla iletildi.");
if (data.success) { //success comes from the return json object
$scope.contact.sendContactResult = $sce.trustAsHtml("Mesajınız başarıyla iletildi.");
$scope.contact.send = false;
$scope.contact.sendContactResult = $sce.trustAsHtml("Message has been sent");
$scope.contact.result = 'bg-success';
}
else {
$scope.contact.sendContactResult = $sce.trustAsHtml("Message no sent");
$scope.contact.result = 'bg-success';
}
});
};
PhpMailer = contact.php
$data= file_get_contents("php://input");
$dataJsonDecode = json_decode($data);
$name = $dataJsonDecode->name;
$email = $dataJsonDecode->email;
$message = $dataJsonDecode->message;
include 'PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'mail.mhz.com.tr';
$mail->Port = 587;
$mail->Username = 'xxx';
$mail->Password = 'xxx';
$mail->SetFrom($mail->Username, $name);
$mail->AddAddress('xxx','INFO');
$mail->CharSet = 'UTF-8';
$mail->Subject = 'xxxxx';
//$mail->MsgHTML('$a');
$mail->Body = "Name: " . $name . "\r\n\r\nEmail:".$email."\r\n\r\nMessage: " . stripslashes($message);
if ($mail->Send())
{
echo 'Mail sent!';
}
else
{
echo 'Mail error ' . $mail->ErrorInfo;
}
$data = array('success' => true, 'message' => 'Thanks! We have received your message.');
echo json_encode($data);
我收到了这封电子邮件。一切正常,但我无法在联系表格中收到success
消息。
答案 0 :(得分:0)
如果您使用角度烤面包机,则需要两个参数:
toastr.success("Success", "Eposta adresiniz sistemimize başarıyla kaydedildi.");
如果是错误,那么
toastr.error("Error", "Error Message.");
如果是自定义烤面包机,那么您需要检查您的应用模块。