mark
mark

Reputation: 619

not able to send email from PHP page

I want to send email from contact page of the my site. I google and it told to use PHP scripts as my domain is LINUX based so I cannot use ASP. I tried couple of them but not able to send. How ever I have used @ECHO to display message, which I got but not the email. Here the codes that I tried:

<?php 

 $userid='[email protected]';
 $subject='New Requirement';

 $Name=$_POST['Name'];
 $Email=$_POST['Email'];
 $Phone=$_POST['Phone'];    
 $Message=$_POST['Message'];

 $body= <<<EOD;
 <br><hr><br>
 Name: $Name <br>
 Email: $Email <br>
 Phone:  $From <br> 
 Message: $Message
EOD;
  $headers='From: $Email';
  mail($userid,$subject,$body,$headers);
  echo "Message send!!!";
?>

And I also tried :

<?php
 $to      = '[email protected]';
 $subject = 'the subject';
  $message = 'hello';
  $headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

if (mail($to, $subject, $message, $headers )) {
ECHO 'Message send successfully';
} 
else {
ECHO 'Please try again, Message could not be sent!';
}  
?>

Can any one tell me what am I missing here.

Upvotes: 0

Views: 117

Answers (2)

Lokesh Jain
Lokesh Jain

Reputation: 579

try this code

$senderName="John";
$senderEmail= "[email protected]";
$recipient = "[email protected]";
$subject ="testmail";
$message="test message";


$headers = "From: " . $senderName . " <" . $senderEmail . ">";

$success = mail($recipient, $subject, $message, $headers );

Upvotes: 0

HEEN
HEEN

Reputation: 4721

Change your if Condition with the below mentioned code, hope it works:-

      $mail=mail($to, "Subject: $subject",$message );
       if($mail){
       echo "Thank you for using our mail form";
     }else{
   echo "Mail sending failed."; 
 }

Upvotes: 1

Related Questions