【问题标题】:My PHP treatement file doesn't works我的 PHP 处理文件不起作用
【发布时间】:2014-04-23 13:12:14
【问题描述】:

我需要一点帮助。我创建了一个文件 traitement.php 来从我的表单中恢复数据,但是当我点击发送按钮时我没有收到任何消息(表单已发送 ....)。

字段:姓名、姓氏、电子邮件和项目目标是必填项,其余不是。

我使用配置良好的 WAMP + sendmail 来发送邮件。另一个 PHP 脚本有效。

<?php

header('Content-type: text/html; charset=utf-8');

    if(isset($_POST) && isset($_POST['form2_prenom']) && isset($_POST['form2_nom']) && isset($_POST['form2_email']) && isset($_POST['form2_telephone']) && isset($_POST['form2_societe']) && isset($_POST['form2_url']) && isset($_POST['form2_secteur']) && isset($_POST['form2_projet']) && isset($_POST['form2_nature']) && isset($_POST['form2_objectif']) && isset($_POST['form2_cible']) && isset($_POST['form2_delai']) && isset($_POST['form2_budget']) && isset($_POST['form2_cahier']) && isset($_POST['form2_identite']) && isset($_POST['form2_souhaits']) && isset($_POST['form2_exemples']) && isset($_POST['form2_dev']) && isset($_POST['form2_services']) && isset($_POST['choix_contact']) && isset($_POST['choix_moment'])) {
        extract($_POST);
        if(!empty($form2_prenom) && !empty($form2_nom) && !empty($form2_email) && !empty($form2_projet) && !empty($form2_objectif)) {

            $to = 'xxxxx@gmail.com'; // My real email

            $subject = 'Contact from the site';

            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'Content-Type: text/html; charset=utf-8' . "\r\n";
            $headers .= 'From:' .$form2_prenom. " " .$form2_email. "\r\n";
            $headers .= 'Reply-To:'.$form2_email. "\r\n";

            $message = 'Surname : $form2_prenom \n';
            $message .= 'Name : $form2_nom \n';
            $message .= 'Email : $form2_email \n';
            $message .= 'Tel : $form2_telephone \n';
            $message .= 'Company : $form2_societe \n';
            $message .= 'URL : $form2_url \n';
            $message .= 'Sector : $form2_secteur \n';
            $message .= 'Project : $form2_projet \n';
            $message .= 'Nature : $form2_nature \n';
            $message .= 'Purpose : $form2_objectif \n';
            $message .= 'Target : $form2_cible \n';
            $message .= 'Deadline : $form2_delai \n';
            $message .= 'Budget : $form2_budget \n';
            $message .= 'Specifications : $form2_cahier \n';
            $message .= 'Identity : $form2_identite \n';
            $message .= 'Wishes : $form2_souhaits \n';
            $message .= 'Examples : $form2_exemples \n';
            $message .= 'Development : $form2_dev \n';
            $message .= 'Services : $form2_services \n';
            $message .= 'To contact : $choix_contact \n';
            $message .= 'The : $choix_moment \n';

            if(mail($to, $subject, $message, $headers)){
                echo "The form has been sent";
            } else {
                echo "The form has not been sent";
            }

        } else {
            echo "You have not filled in all the fields";
        }
    }
?>

【问题讨论】:

  • 请发布更多关于底层操作系统和项目设置的信息,可能是配置。
  • 好的,我更新了我的帖子:我使用配置良好的 WAMP + sendmail 来发送邮件。另一个 PHP 脚本有效。
  • 正如 Rahul 所说,使用 PHPMailer 之类的东西来执行此操作 - 您的脚本容易受到标头注入攻击,并且可能会导致错误编码的消息,因为它没有进行过滤或格式化。电子邮件一点都不简单!

标签: php forms


【解决方案1】:

首先将所有行转换如下:

$message = 'Prénom : $form2_prenom \n';

收件人:

$message = "Prénom : $form2_prenom \n";

或者:

$message = 'Prénom : '.$form2_prenom.' \n';

第二:使用phpMailer类发送邮件。访问:https://github.com/PHPMailer/PHPMailer

【讨论】:

  • 您好,谢谢。我将 Wamp 与 sendmail 一起使用,这适用于另一个 PHP 文件
【解决方案2】:

从脚本发送电子邮件需要正确配置您的服务器。查看this 了解更多信息。

【讨论】:

  • 我使用配置良好的 WAMP + sendmail 来发送邮件。另一个 PHP 脚本有效。
猜你喜欢
  • 2013-11-02
  • 1970-01-01
  • 2022-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-21
  • 2016-01-09
相关资源
最近更新 更多