1

I have done with my contact form but I received an error showing message “couldn’t be sent”. I have no errors showing except the line of sending mail which is:

$isSuccess = mail($to, $subject, $message, $headers);

Also, I have modified the code according the forum members’ suggestions and still I am receiving the same error.

Could help me with that? I have also read the PHP documentation and I followed all instructions but still no result.

HTML code:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<h2>Contact Form</h2>
<p><span style="color: red" >*Required field</span></p>
<form action="contact.php" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
 First Name:<input type="text" name="fname"><span style="color: red" >*</span><br><br>
 Last Name:<input type="text" name="lname"><span style="color: red" >*</span><br><br>
 E-mail:<input type="text" name="email"><span style="color: red" >*</span><br><br>
 Telephone:<input type="text" name="tel"><br><br>
 Designation:<select name="design">
    <option value="Architectural Engineer">Architectural Engineer</option>
    <option value="Structural Engineer">Structural Engineer</option>
    <option value="Draughts-man">Draughts-man</option>
    <option value="Receptionist">Receptionist</option>
    <option value="Secertary">Secertary</option>
   </select><br><br>
   Country Applied From:<select name="country">
  <option value="">Country...</option>
  <option value="Afganistan">Afghanistan</option>
  <option value="Albania">Albania</option>
</select><br><br>
 Message:<textarea name="comment"></textarea> <br><br>
 Upload Your Resume:<span style="color: red" >*</span><input type="file" name="uploaded_file"><br><br> 
 <input type="submit" name="submit" value="Submit">
 <input type="reset" value="Clear">
</form>
</body>
</html>

PHP code:

<?php

if(isset($_POST['submit']))
{

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$design = $_POST['design'];
$country = $_POST['country'];
$comment = $_POST['comment'];


$to = 'eng.bolaraafat@hotmail.com';
$subject = 'Contact Form';
$message = 'From: '.$fname .$lname."\r\n";
           'E-mail: '.$email."\r\n";
           'Telephone: '.$tel."\r\n";
           'Designation: '.$design."\r\n";
           'Country Appled From: '.$country."\r\n";
           'Message: '.$comment."\r\n";
$headers = "From:" .$email. "\n" .


    $isSuccess =  mail($to, $subject, $message, $headers);

if( $isSuccess == true ) { // if mail is successfully sent 
   echo "Message sent successfully...";
}else{
   echo "Message could not be sent...";
}
}

?>
Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
paulrf
  • 37
  • 8
  • You seem to have a type *before* you send it.... as you don't close your `$headers` value... Have something more like: `$headers = "From: ".$email."\n";` – Nytrix Mar 07 '17 at 06:54
  • If you are using from localhost check this http://stackoverflow.com/questions/18288007/php-send-mail-from-localhost – Aman Rawat Mar 07 '17 at 06:55
  • @AmanRawat thanks alot for your help it works now i appreciate your help many thanks to you – paulrf Mar 07 '17 at 07:52

1 Answers1

0

i have found a solution by the help of @amanrawat which is installing mail server on local web host and not PHP mailer there is a way more easier than that which is test mail server tool where you can follow istructions from this link:
https://www.youtube.com/watch?v=FSpkJl_YCOE&t=279s
thanks for everyone who helped me.

paulrf
  • 37
  • 8