[英]PHPmailer Function Send Mail from PHP
so i am working on a contact form in html and i linked it to a sendmail.php file, as i still in the early process i was testing if fields are empty echo something... nothing is appearing. 所以我正在使用html中的联系表单,因此我将其链接到sendmail.php文件,因为我仍在早期过程中,我正在测试字段是否为空回显什么...什么也没出现。 Please check my code it's still in it's early stage i'm afraid i have missed something out: 请检查我的代码,它仍处于早期阶段,恐怕我错过了一些东西:
HTML 的HTML
<form action="sendmail.php" method="post" >
<table width="101" border="0">
<tr>
<th scope="col">Full Name:</th>
</tr>
<tr>
<th width="95" scope="col"><input type="text" name="name" id="to" placeholder="Full Name" /></th><!-- -->
</tr>
<tr>
<th scope="row">Telephone:</th>
</tr>
<tr>
<th scope="row"><input type="text" name="telephone" id="telephone"placeholder="Telephone" />
</tr>
<tr>
<th scope="row">Subject:</th>
</tr>
<tr>
<th scope="row"><input type="text" name="subject" id="subject" placeholder="Subject" /></th>
</tr>
<tr>
<th scope="row">Message:</th>
</tr>
<tr>
<th scope="row"><textarea name="body" id="body" cols="45" rows="5" placeholder="Message"></textarea></th>
</tr>
<tr>
<th scope="row"> </th>
</tr>
<tr>
<th scope="row"><input type="submit" name="submit" id="submit" value="Submit" /></th>
</tr>
</table>
</form>
PHP 的PHP
<?php
session_start();
require_once 'libs/phpmailer/PHPMailerAutoload.php/';
$errors = array();
//if values are null echo null values
//in my case i kept null on purpose to see if working
//getting nothing
if(isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body']))
{
echo 'Null values';
}
?>
EDIT: 编辑:
require_once 'libs/phpmailer/PHPMailerAutoload.php/';
Try this? 尝试这个?
require_once 'libs/phpmailer/PHPMailerAutoload.php';
You didn't ask to do something as far as I can see. 据我所知,您没有要求做某事。 This might work (all in one file, no need to create a second file) 这可能有效(全部在一个文件中,无需创建第二个文件)
<?
if($_SERVER['REQUEST_METHOD']=="POST")
{
if(strlen($_POST['name']) == 0)
{ $error_msg ="- Please, provide us with your name.<br>"; }
if(strlen($_POST['*****WHATEVER*****']) == 0)
{ $error_msg ="- Fill in your problem :D.<br>"; }
if(!empty($error_msg))
{
echo "<b>Your message can't be send due to the following reason:</b> <br><br>";
echo $error_msg;
echo "<br>Click on <a href='javascript:history.back(1)'>Go back</a> and provide us with your name.<br><br>";
}
else
{
$recipient = "WHO NEEDS TO RECEIVE???";
$subject = "Subject, can be filled in via input field if you like";
$header = "From: " . $_POST['email'] . "\n";
$mail_body = "Contact script was used on " . date("d-m-Y") . " at " . date("H:i") . "h.\n";
$mail_body .= "Text you like to read:\n";
$mail_body .= "Name: " . $_POST['name'] . "\n";
$mail_body .= "\n\n -- End of contact --";
mail($recipient, $subject, $mail_body, $header);
print "Your mail is sent and whatever you like to tell them ;)";
}
}
else
{
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST" name="contact">
******Then add your tables and label them as you please.****
Your line 你的线
if(isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body'])){....}
should be 应该
if(!isset($_POST['name'],$_POST['telephone'],$_POST['subject'],$_POST['body'])){.....}
On submit input type text are never NULL
. 在提交输入类型时,文本永远不会为NULL
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.