我正在编辑表单,我想在用户填写并发送时收到邮件。我之前收到过邮件变量,比如:名称:$ name。现在contact.php返回一个空白页面,我无法收到该表格作为邮件。
我之前尝试过,
$body_message = 'Name: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Message: ' . $message;
但它不起作用。那也是,
$mail->Body = '<b>You have a reservation!</b>
Name: $name
Surname: $surname
Phone: $phone
Mail: $mail
Address: $address
Services: $check
';
现在我的代码:
$name = $_POST['name'];
$surname = $_POST['surname'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$address= $_POST['address'];
if(!empty($_POST['check_list'])) {
foreach($_POST['check_list'] as $check) {
return $check;
}
}
$mail->Subject = 'Reservation';
$mail->Body = '<b>You have a reservation!</b></br>'
.'Name: '.$name.'</br>'
.'Surname: '.$surname.'</br>'
.'Mail: '.$mail.'</br>'
.'Phone: '.$phone.'</br>'
.'Address: '.$address.'</br>'
.'Services: '.$check;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
header('Location: index.php');
exit();
}
答案 0 :(得分:1)
您的代码有2个错误。
1。)您可以从表单中为$ mail分配电子邮件地址。然后访问$ mail实例,这应该被误认为是PHPMailer实例。
setVariables
2。)你正在退出foreach中的执行
class App extends React.Component {
componentWillMount() {
const relay = this.props.relay;
relay.setVariables({ userId: this.props.userStore.id});
}
...
}
export default Relay.createContainer(connect(fullStoreSelector)(App), {
initialVariables: {
userId: 'NULL' // we need to pass a dud string here that
// returns empty data because we have to
// set relay variables in componentDidMount
},
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
user(id: $userId) {
id
firstName
}
}
`
}
});
<强>修正强>
$mail = $_POST['mail'];
....
....
$mail->Subject = 'Reservation';
$mail->Body = '<b>You have a reservation!</b></br>'
....
....
答案 1 :(得分:0)
这一行:
$mail = $_POST['mail'];
表示$mail
是包含电子邮件的字符串。
而且:
$mail->Subject
表示$mail
是某个类的实例。
是某个类的字符串还是实例?你能说出来吗?
正如已经注意到的那样 - 在return
中使用foreach
会导致您的脚本或您的功能(无论您拥有什么内容)停止执行脚本或结束功能执行。