Reputation: 53
Below is the code for sending mail directly from form but it is not working.
<?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 = '[email protected]';//<== 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 = "[email protected]";//<== 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>");
}
}
?>
Below is the code of form.
<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>
Error : $headers must be an array
Upvotes: 0
Views: 1626
Reputation: 5041
I believe you have the wrong number of parameters for $smtp->send
$email_subject should be in the header as 'Subject' => $email_subject
Your call should be something like:
$smtp->send($to, $headers, $email_body);
Upvotes: 1
Reputation: 942
By googling for Mail::factory I found the following: https://pear.php.net/manual/en/package.mail.mail.factory.php
Is this the class you are using? If yes, you are passing wrong arguments to the send method: https://pear.php.net/manual/en/package.mail.mail.send.php
mixed send (mixed $recipients, array $headers, string $body)
Upvotes: 0