Php 电子邮件表单发送空白电子邮件
我在我的网站上有一个电子邮件表单,当我试图发送电子邮件时,我收到了它,但它是空白的,里面什么都没有 我是php新手,所以我对php几乎没有经验 我一直在寻找,但找不到解决我问题的办法 请帮忙 这是我的代码:Php 电子邮件表单发送空白电子邮件,php,forms,email,Php,Forms,Email,我在我的网站上有一个电子邮件表单,当我试图发送电子邮件时,我收到了它,但它是空白的,里面什么都没有 我是php新手,所以我对php几乎没有经验 我一直在寻找,但找不到解决我问题的办法 请帮忙 这是我的代码: <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php"> <div class="col-sm-5 col-
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required>
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
名字*
电子邮件*
电话
公司名称
主题*
信息*
提交消息
PHP文件:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = @trim(stripslashes($_POST['name']));
$email = @trim(stripslashes($_POST['email']));
$subject = @trim(stripslashes($_POST['subject']));
$message = @trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 's.design.mg@gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>
查看邮件函数并在pramiter中设置变量并删除@
查看内容
设置标题变量请参见上文…尝试此操作
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = stripslashes($_POST['name']);
$email = stripslashes($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
$email_from = $email;
$email_to = 's.design.mg@gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" .
'Email: ' . $email . "\n\n" .
'Subject: ' . $subject . "\n\n" .
'Message: ' . $message;
$header = "MIME-Version: 1.0" . "\r\n";
$header .= 'From:'.$email_from . "\r\n";
$success = @mail($email_to, $subject, $body,$header );
echo json_encode($status);
die;
?>
您也可以使用escape\u string函数检查输入的值。var_dump name,email等。感谢各位@版主和@R P Digital Revolution,我确实尝试了你们的建议,但仍然不起作用,我确实收到了一封电子邮件,里面什么都没有。这是我收到的信息:姓名:电子邮件:主题:邮件:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = stripslashes($_POST['name']);
$email = stripslashes($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
$email_from = $email;
$email_to = 's.design.mg@gmail.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" .
'Email: ' . $email . "\n\n" .
'Subject: ' . $subject . "\n\n" .
'Message: ' . $message;
$header = "MIME-Version: 1.0" . "\r\n";
$header .= 'From:'.$email_from . "\r\n";
$success = @mail($email_to, $subject, $body,$header );
echo json_encode($status);
die;
?>