Ошибка отправки почты PHP: заголовок должен быть массивом - PullRequest
0 голосов
/ 05 мая 2018

Ниже приведен код для отправки почты непосредственно из формы, но он не работает.

<?php
ini_set("include_path", '/home/ny1zdip8aag5/php:' . ini_get("include_path") );
include('Mail.php');
if (isset($_POST['submit'])) {

    $name = $_POST['name'];
    $email = $_POST['email'];
    $mobile = $_POST['mobile'];
    $address = $_POST['address'];
    $pan = $_POST['pan'];
    $aadhar = $_POST['aadhar'];
    $comp = $_POST['comp'];
    $amount = $_POST['amount'];
    $loss = $_POST['loss'];
    $message = $_POST['message'];


    $email_from = 'support@picors.com';//<== update the email address
    $email_subject = "New Form submission from $name";
    $email_body = "You have received a new message from the user $name.\n".
        "Here is the message:\n $message".
        "E-mail:\n $email".
        "Mobile:\n $mobile".
        "Address:\n $address".
        "PAN:\n $pan".
        "AADHAR:\n $aadhar".
        "Complainant Company Name:\n $comp".
        "Service Amount Paid To Company:\n $amount".
        "Loss Amount:\n $loss".

    $to = "suport@picors.com";//<== update the email address
    $headers = array ('From' => $email,
      'To' => $email,
      'Subject' => $name);
    $host = "**************";
    $username = "*************";
    $password = "***********";
    $smtp = Mail::factory('smtp',
      array ('host' => $host,
        'auth' => "PLAIN",
    'socket_options' => array('ssl' => array('verify_peer_name' => false)),
        'username' => $username,
        'password' => $password));
        $mail = $smtp->send($to,$email_subject,$email_body,$headers);
    if (PEAR::isError($mail)) {
      echo("<p>" . $mail->getMessage() . "</p>");
     } else {
      echo("<p>Message successfully sent!</p>");
     }
}

?> 

Ниже приведен код формы.

<form method="post">
    <div class="form-group">
        <input type="text" name="name" class="form-control input-text" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />

    </div>
    <div class="form-group">
        <input type="email" class="form-control input-text" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />

    </div>
    <div class="form-group">
        <input type="text" class="form-control input-text" name="mobile" id="mobile" placeholder="Mobile Number" data-rule="minlen:4" data-msg="Please enter valid mobile number" />

    <div class="form-group">
        <input type="text" class="form-control input-text" name="address" id="Address" placeholder="Address" data-rule="minlen:4" data-msg="Please enter address here" />

    </div>
    <div class="form-group">
        <input type="text" class="form-control input-text" name="pan" id="pan" placeholder="PAN Number" data-rule="minlen:4" data-msg="Please enter PAN number here" />

    </div>
    <div class="form-group">
        <input type="text" class="form-control input-text" name="aadhar" id="aadhar" placeholder="ADHAAR Number" data-rule="minlen:4" data-msg="Please enter ADHAAR Number here" />

    </div>
    <div class="form-group">
        <input type="text" class="form-control input-text" name="comp" id="comp" placeholder="Complainant Company Name" data-rule="minlen:4" data-msg="Please enter complainant company name here" />

    </div>
    <div class="form-group">
        <input type="text" class="form-control input-text" name="amount" id="amount" placeholder="Service Amount Paid To Company" data-rule="minlen:4" data-msg="Please enter service amount paid to company here" />

    </div>
    <div class="form-group">
        <input type="text" class="form-control input-text" name="loss" id="loss" placeholder="Loss Amount" data-rule="minlen:4" data-msg="Please enter loss amount here" />

    </div>
    <div class="form-group">
        <textarea class="form-control input-text text-area" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>

    </div>

    <div class="text-center"><input type="submit" name="submit" class="btn btn-default submit" value="Send Message" align="middle"/></div>

Ошибка: $ заголовки должны быть массивом

Ответы [ 2 ]

0 голосов
/ 05 мая 2018

Я считаю, что у вас неверное количество параметров для $smtp->send

 $email_subject should be in the header as 'Subject' => $email_subject

Ваш звонок должен быть примерно таким:

 $smtp->send($to, $headers, $email_body);
0 голосов
/ 05 мая 2018

По поиску в Mail :: factory я обнаружил следующее: https://pear.php.net/manual/en/package.mail.mail.factory.php

Этот класс вы используете? Если да, вы передаете неверные аргументы методу send: https://pear.php.net/manual/en/package.mail.mail.send.php

mixed send (mixed $recipients, array $headers, string $body)
...