嗨,我是新来的PHP和邮戳,并试图获取表单提交设置为我的电子邮件。我的电子邮件工作,但是我不能得到它显示的标题(“位置:thanks.php)页任何帮助将不胜感激感谢使用邮戳和PHP
require("postmark.php");
$postmark = new Postmark("API KEY","[email protected]","$email");
if($postmark->to("[email protected]")->subject("Mission Woodshop | " . $name)->plain_message($email_body)->send()){
exit;
}
header("Location: thanks.php");
exit;
<?php
/**
* This is a simple library for sending emails with Postmark created by Matthew Loberg (http://mloberg.com)
*/
class Postmark{
private $api_key;
private $data = array();
function __construct($apikey,$from,$reply=""){
$this->api_key = $apikey;
$this->data["From"] = $from;
$this->data["ReplyTo"] = $reply;
}
function send(){
$headers = array(
"Accept: application/json",
"Content-Type: application/json",
"X-Postmark-Server-Token: {$this->api_key}"
);
$data = $this->data;
$ch = curl_init('http://api.postmarkapp.com/email');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$return = curl_exec($ch);
$curl_error = curl_error($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// do some checking to make sure it sent
if($http_code !== 200){
return false;
}else{
return true;
}
}
function to($to){
$this->data["To"] = $to;
return $this;
}
function subject($subject){
$this->data["subject"] = $subject;
return $this;
}
function html_message($body){
$this->data["HtmlBody"] = "<html><body>{$body}</body></html>";
return $this;
}
function plain_message($msg){
$this->data["TextBody"] = $msg;
return $this;
}
function tag($tag){
$this->data["Tag"] = $tag;
return $this;
}
}
显示的任何错误? – Mooseman 2015-02-06 20:00:00
如果“发送”成功,您只需从“if”块内“退出”您的代码。头(...)调用需要在该块内。 – mrunion 2015-02-06 20:00:55
Calvin,你能链接到你用来访问邮戳的“postmark.php”文件/库吗?正如其他人在发送位置标题之前if块中的“退出”行似乎正在退出脚本,但无法在不查看“postmark.php”源代码的情况下对其进行验证 – 2015-02-06 20:55:01