Click here to Skip to main content
15,885,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<!DOCTYPE html>
<head>
<title>Form submission</title>
</head>
<body>

<form action="form.php" method="POST">
First Name: <input type="text" name="first_name"><br>
Last Name: <input type="text" name="last_name"><br>
Subject: <input name="subject" type="text" /><br />
Email: <input type="text" name="email"><br>
Message:<br><textarea rows="5" name="message" cols="30"></textarea><br>
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

PHP
<?php
  $admin_email = "someone@gmail.com";
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  $subject = $_POST['subject'];
  $email = $_POST['email'];
  $message = $_POST['message'];

  //send email
 mail($email, "$subject", $message, "From:" . $admin_email);
?>


For me the code looks correct.But the email is not received by the recipient.
Problem with my code or anything else?
Please suggest me ideas or any links to implement this in my localhost.
Posted

1 solution

Take a look at this[^] example:

PHP
<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to,$subject,$txt,$headers);
?>


mail(to,subject,message,headers,parameters);

Parameters:

to
Required. Specifies the receiver / receivers of the email

subject
Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters

message
Required. Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900