Send email with data from a form – code.

Want to send email with data from a form? Here is the sample code for beginners.

Objective: Take values from an online from about desired profile (as in a recruitment agency) and send email with details to specified email id with the Job Requirement Details.

Description of approach: We are writing here script to be used which is called from an HTML form. This script send an email to specified email id with the values entered in the HTML form.

Script:

$formgood = true;
$to = “email@mydomain.com”;
//Please change above email to your e-mail address and customize the message below to your requirement. The fields below will be as per your form.
$message = ” $contact has submitted a inquiry form. \n
\n
You can reply to $email”;
$enquiry1=”Hello,\n
\n
following details entered at website www.mysite.com\n
\n
Company name: $cname\n
Address:$add.\n
Contact person:$contact\n
Phone:$phone.\n
Faxno:$fax.\n
Email:$email.\n
Web site:$web.\n
About company:$aboutcom.\n
Position:$position.\n
Reporting to:$reporting.\n
Location:$location.\n
Travel:$travel.\n
No of Openings:$openings.\n
Role:$role.\n
Education:$edu.\n
Experience in years:$exp1.\n
Experiencedetails:$exp2.\n
Skills:$skills.\n
Salary: $sal.\n
Remarks:$remarks.\n
Recruitment Process: $rec;\n
\n
Thankyou.\n
\n
www.career-first.com\n
\n
email@mydomain.com.”;

if ($formgood) { if (mail ($to, “A enquiry form has been submitted by $name”, $enquiry1, “From: $email\n”)) { //echo nl2br (“Thank you for submitting this form. We will review your comments and contact you shortly\n\n”);}
else {echo “An error has occurred. Please contact the webmaster.”;} if (mail ($email, “Thank you for submitting this form. We will review your comments and contact you shortly”,$enquiry1, “From: $to\n”)) { //echo nl2br(“Thank you for submitting this form. We will review your comments and contact you shortly. \n\n”); header (“location:thankyou.htm”);}
else {echo “An error has occurred. Please contact the webmaster.”;} }
else { echo “Please review the comments above and try again.”; echo ”;}?>

May be good for beginners?

Share

Leave a Reply

Enter your email address to get Fresher Jobs: