0

i have a registration form:

<h2>PHP Form Validation Example</h2>
<form method="post" action="sendmail.php"> 
Name: <input type="text" name="name">
<br><br>
E-mail: <input type="text" name="email">
<br><br>
Website: <input type="text" name="website">
<br><br>
Comment: <textarea name="comment" rows="5" cols="40"></textarea>
<br><br>
<input type="submit" name="submit" value="Submit"> 
</form>
</body>
</html>

and i wrote php code where a mail can be send like this:

<?php
 $name = $_POST['name'];
 $to = $_POST['email'];
 $msg = $_POST['comment'];
 sendMail($to);
 function sendMail($to){
 $subject = "Thanks for registring.";
 $message = "We are glad that you have posted your problems with us.";
 //$header = "From:".$to;

  $headers = array(
  'From' => $email,
  'To' => $to,
  'Subject' => $subject
  );

  $smtp = Mail::factory('smtp', array(
    'host' => 'ssl://smtp.live.com',
    'port' => '587',
    'auth' => true,
    'username' => 'USERNAME',
    'password' => 'PASSWORD'
  ));

  $pmailing = $smtp->send($to, $headers, $body);
 //$retval = mail ($to,$subject,$message,$header);
 //$mmsg = 'Receiver: mymail@gmail.com';
 if( $pmailing == true )  
 {
  echo "Message sent successfully...";
  //$mmsg = "Mail sent.";
 }
 else
 {
  echo "Message could not be sent...";
  //$mmsg = "Mail not send.";
  echo'<script> window.location="re_enter.html"; </script> ';
 }
}
?>

it is showing "Mail" is not acceptable. So suggest me, i have edited my code with your code which you have shared. Do i require to add any library or any as such to execute this SMTP code.

Pallavipradeep
  • 101
  • 1
  • 2
  • 14

2 Answers2

0

For configure mail on xmapp Localhost

Go to xampp/php/php.ini open and search

 [mail function]
    SMTP = mail.yourserver.com
    smtp_port = 25

and save file and restart your apache For more info :- How to configure XAMPP to send mail from localhost?

for sending mail() php function is

$retval = mail($to, $subject, $message);
if($retval)
// your stuff here

or use phpmailer

Community
  • 1
  • 1
Rakesh Sharma
  • 13,680
  • 5
  • 37
  • 44
  • hi Rakesh, i have specified SMTP=smtp.gmail.com and re-strated apache still am not able to receive any mail but just a message with message send successful – Pallavipradeep Mar 05 '14 at 07:35
  • @Pallavipradeep You need some more settings to be filled in: [How to send email from XAMPP (PHP)](https://expertester.wordpress.com/2010/07/07/how-to-send-email-from-xampp-php/). You haven't filled in any user credentials. `SMTP = smtp.gmail.com; smtp_port = 587; sendmail_from = [your_gmail_username]@gmail.com; sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"` – BlueCacti Mar 05 '14 at 08:43
  • Rakesh, it is not working after doing specific changes to the code – Pallavipradeep Mar 05 '14 at 08:58
0

try this code.this is demo code.Make changes according to your requirement.

<?php
$from = $_POST['EmailAddr']; //email id of applicant.
$to = 'YOUR MAIL ID';
$subject = 'Call Back Enquiry';
$fullname=$_POST['Name'];
$mobile=$_POST['PhoneMobile'];
$email=$_POST['EmailAddr'];
$message=$_POST['YourMessage'];
$body="Full Name:".$fullname."\n\n"."Mobile:".$mobile."\n\n"."Email:".$email."\n\n"."Message:".$message;

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);

$smtp = Mail::factory('smtp', array(
        'host' => 'ssl://smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => 'YOUR MAIL ID',
        'password' => 'PASSWORD'
    ));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
   // echo('<p>Message successfully sent!</p>');
}
?>
King-of-IT
  • 578
  • 4
  • 18