doubi7739 2018-07-19 20:39
浏览 57

联系表格PHP - 从特定电子邮件发送[重复]

I have a Contact form on my website, works fine. Issue comes about when the contact form is sent to my email, it goes into my spam folder because the email the form is sent from is a random email address.

Is there a way to send the form to my email using a trusted email address?

 <?php
    // Define some constants
    define( "RECIPIENT_NAME", "Greg Collins" );
    define( "RECIPIENT_EMAIL", "maxacollins@gmail.com" );


// Read the form values
$success = false;
$sendername = isset( $_POST['username'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['username'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$senderSubject = isset( $_POST['subject'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['subject'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";

// If all values exist, send the email
if ( $sendername && $senderEmail && $senderSubject && $message) {
  $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
  $headers = " G.C. Environmental.com - Contact Form Message ";
  $msgBody = " 
  Name: " . $sendername . "
  From: " . $senderEmail . " <" . $senderSubject . ">
  Message: " . $message . "  
  ";
  $success = mail( $recipient, $headers, $msgBody );

  //Set Location After Successsfull Submission
  header('Location: contact.html?message=Successfull');
}

else{
    //Set Location After Unsuccesssfull Submission
    header('Location: index.html?message=Failed');  
}

?>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
    • ¥15 cs loadimage运行不了,easyx也下了,没有用
    • ¥15 r包runway详细安装教程
    • ¥15 Html中读取Json文件中数据并制作表格
    • ¥15 谁有RH342练习环境
    • ¥15 STM32F407 DMA中断问题
    • ¥15 uniapp连接阿里云无法发布消息和订阅
    • ¥25 麦当劳点餐系统代码纠错
    • ¥15 轮班监督委员会问题。
    • ¥20 关于变压器的具体案例分析