duanjiao3686 2013-08-01 10:03
浏览 21
已采纳

PHP邮件功能 - 需要帮助[关闭]

I need a slight hand with getting my PHP mail function working correctly.

This is what I currently have, within the header of my php file:

<?php
require_once('common.php');

require_once('mailer.php');

if (isset($_POST['submitBtn']))
{
    // Get user input
    $conName  = isset($_POST['conName']) ? $_POST['conName'] : '';
    $conEmail = isset($_POST['conEmail']) ? $_POST['conEmail'] : '';
    $conPhone = isset($_POST['conPhone']) ? $_POST['conPhone'] : '';
    $conNatureof = isset($_POST['conNatureof']) ? $_POST['conNatureof'] : '';
    $conSubject = isset($_POST['conSubject']) ? $_POST['conSubject'] : '';
    $conMessage = isset($_POST['conMessage']) ? $_POST['conMessage'] : '';

    // Try to send the email
    $error = sendMail($conName,$conEmail,$conPhone,$conNatureof,$conSubject,$conMessage);
}   
?>

This is currently within the body of my PHP file:

<?php if ((!isset($_POST['submitBtn'])) || ($error != '')) {?>
 <form method="post" action="contact.php" enctype="multipart/form-data">

<p><label for="conName">Name:<span class="required">*</span></label><input name="conName" id="conName" type="text" class="input"/></p>
<p><label for="conEmail">Email:<span class="required">*</span></label><input name="conEmail" id="conEmail" type="text" class="input" /></p>
<p><label for="conPhone">Phone:</label><input name="conPhone" id="conPhone" type="text" class="input" /></p>
<p><label for="conNatureof">Nature of enquiry:<span class="required">*</span></label>
<select name="conNatureof" class="input" id="conNatureof">
  <option value="-">-- Please Select --</option>
  <option value="interested">Interested in joining</option>
  <option value="job">Job enquiry</option>
  <option value="other">Other</option>
  <option value="question">Question about membership</option>
</select></p>
<p><label for="conSubject">Subject:<span class="required">*</span></label><input name="conSubject" id="conSubject" type="text" class="input"/></p>
<p>Message:<span class="required">*</span>
<textarea name="conMessage" cols="40" rows="5" class="textarea" id="conMessage"></textarea></p>
<div class="buttonHolder">
<input class="text" type="submit" name="submitBtn" value="Submit" />
</div>
</form>
<?php } ?>

Along with my mailer.php file having the sendMail function as this:

function sendMail($conName,$conEmail,$conPhone,$conNatureof,$conSubject,$conMessage)
{

//String to hold the error messages
$errorText = '';

//START VALIDATION OF USER INPUT

//Validating name
if($conName == "")
{
    $errorText = $errorText . "- Please enter a name<br />";
}



//Validating email address
//Must be a valid email address and is compulsory
if($conEmail == "")
{
    $errorText = $errorText . "- Please enter an email address<br />";
}
elseif (!filter_var($conEmail, FILTER_VALIDATE_EMAIL)) 
{
    $errorText = $errorText . "- Email address was invalid<br />";
}


//Validating enquiry type
if($conNatureof == "-")
{
    $errorText = $errorText . "- Please select your nature of enquiry<br />";
}

//Validating subject and message
if($conSubject == "")
{
    $errorText = $errorText . "- Please enter a subject<br />";
}

if($conMessage == "")
{
    $errorText = $errorText . "- Please enter a message<br />";
}


// If everything is OK, send the email
if ($errorText == '') 
{
    $to = "jademulholland@hotmail.com";
    $subject = $conSubject;
    $message = $conMessage;
    $from = $conEmail;
    $headers = "From:" . $conName;
    mail($to,$subject,$message,$headers);
}

return $errorText;
}

I know that most of that code is not necessary to diagnose the problem, although I thought it would be appropriate to give as much as possible.

All help is greatly appreciated, Thanks

  • 写回答

1条回答 默认 最新

  • duanbimo7212 2013-08-01 10:11
    关注

    You are developing contact form with validation . please follow the link you will get idea else google it contact form with validation

    else google it try in google

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误