亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

debian 9 上 js + php 的 Sendmail 問題

debian 9 上 js + php 的 Sendmail 問題

PHP
HUH函數 2023-04-28 17:09:40
我在用我的 VPS 服務器發送郵件時遇到了問題。我的服務器安裝了 PHP 和 sendmail。我嘗試從 HTML 表單發送電子郵件,該表單在 JS 中檢查然后以 HTML 發送,請求啟動良好但未發送任何內容。我的 JS 代碼:submitMail() {      const emailValue = document.getElementById('mail').value;      const subjectValue = document.getElementById('subject').value;      const messageValue = document.getElementById('text').value;      const xhr = new XMLHttpRequest();      xhr.open('POST', 'https://ag-dev.fr/mailform.php', true);      xhr.setRequestHeader('Content-Type', 'application/json');      xhr.onreadystatechange = () => {        if (xhr.readyState === 4 && xhr.status === 200) {          this.sendComplet();        }      };      xhr.send(JSON.stringify({        email: emailValue,        subject: subjectValue,        message: messageValue,      }));    },我的 PHP 代碼:<?php  if (!empty($_POST['message']))  {      $to = '[email protected]';      $from = $_POST['email'];      $subject = $_POST['subject'];      $message = $_POST['message'] . "\n\n\n\n Ceci est un message envoyé depuis le formulaire de contact. Pour répondre à ce mail, envoyez un mail à l'adresse suivante : " . $_POST['email'];      $headers  = 'MIME-Version: 1.0\r\n';      $headers .= 'Content-type: text/html; charset=iso-8859-1\r\n';      $headers .= 'To: Guyomar Alexis <[email protected]>\r\n';      $headers .= 'From: ' . ' <' . $from . '>\r\n';      mail($to,$subject,$message,$headers);  }?>我使用 sendmail 在我的命令行服務器上運行測試,我收到郵件沒有問題。我認為我的代碼或我的配置服務器有問題。如果有人知道這可能來自哪里......
查看完整描述

1 回答

?
開滿天機

TA貢獻1786條經驗 獲得超13個贊

提供 JSON POST with PHP 鏈接。我這樣解決我的問題:


<?php

  $data = json_decode(file_get_contents('php://input'), true);

  if (!empty($data))

  {

      $to = '[email protected]';

      $from = $data['email'];

      $subject = utf8_decode($data['subject']);

      $message = utf8_decode($data['message']) . utf8_decode("\n\n\n\n Ceci est un message envoyé depuis le formulaire de contact. Pour répondre à ce mail, envoyez un mail à l'adresse suivante : " . $from);

      $headers  = 'MIME-Version: 1.0\r\n';

      $headers .= 'Content-type: text/html; charset=utf-8\r\n';

      $headers .= 'To: Guyomar Alexis <[email protected]>\r\n';

      $headers .= 'From: ' . ' <' . $from . '>\r\n';

      mail($to,$subject,$message,$headers);

  }

?>

現在一切都運行良好。


查看完整回答
反對 回復 2023-04-28
  • 1 回答
  • 0 關注
  • 206 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號