-1

My form has 5 steps, every steps works fine and session variable pass to each pages. after submission, i want data to emailed back to admin. i have tried to write this, but it returns 500 error or white screen. please correct this where i am wrong here. here below is the codes for email processing after submission.

<?php
session_start();

$email_from = 'no-reply@indianvisaservice.org';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $_SESSION['givenname']."\r\n";.
    "Here is the message:\n $message"

$message = Application Reference No - $_SESSION['appid'] ."\r\n";
$message .= type of VISA Application - $_SESSION['visatype']."\r\n";
$message .= Port of Arrival - $_SESSION['arrivalport']."\r\n";
$message .= Application type - $_SESSION['appltype']."\r\n";
$message .= Applicant Name - $_SESSION['givenname']."\r\n";
$message .= Applicant Sex - $_SESSION['applsex']."\r\n";
$message .= Applicant Marital Status - $_SESSION['martstat']."\r\n";
$message .= Applicant Birthdate - $_SESSION['birthdate']."\r\n";
$message .= Applicant Passport No - $_SESSION['passportno']."\r\n";
$message .= Country of Birth - $_SESSION['countrybrth'] ."\r\n";
$message .= Religion of Applicant - $_SESSION['religionxx']."\r\n";
$message .= Educational Qualification - $_SESSION['edu_id']."\r\n";
$message .= Application Nationality by - $_SESSION['nationality_by']."\r\n";
$message .= Passport Issue Place - $_SESSION['issueplace'] ."\r\n";
$message .= Passport Issue date - $_SESSION['issuedate']."\r\n";
$message .= Visual Identification - $_SESSION['visual_d_mark']."\r\n";
$message .= is there Other Passport have - $_SESSION['tab']."\r\n";
$message. = Other Passport No - $_SESSION['oth_ppt_no'] ."\r\n";
$message .= Other Passport Issue Place - $_SESSION['oth_ppt_issue_place']."\r\n";
$message .= Other Passport Issue Date - $_SESSION['previssuedate']."\r\n";
$message .= Other Passport Nationality - $_SESSION['oth_ppt_nationality']."\r\n";
$message .= Other Passport Country Issue - $_SESSION['country_issue'] ."\r\n";
$message .= Father Name - $_SESSION['fthrname']."\r\n";
$message .= Father Nationality - $_SESSION['fathr_nation_id'] ."\r\n";
$message .= Father Previous Nationality - $_SESSION['fthrprevntl']."\r\n";
$message .= Father Place of Birth - $_SESSION['fthrpob']."\r\n";
$message .= Father City of Birth - $_SESSION['fthrcob']."\r\n";
$message .= Mother Name - $_SESSION['mthrname'] ."\r\n";
$message .= Mother Nationality - $_SESSION['mthr_nation_id']."\r\n";
$message .= Mother Previous Nationality - $_SESSION['mthrprevntl']."\r\n";
$message .= Mother Place of Birth - $_SESSION['mthrpob']."\r\n";
$message .= Mother City of Birth - $_SESSION['mthrcob']."\r\n";
$message .= Duration of Visit - $_SESSION['visitduration']."\r\n";
$message .= No of Visa Entry - $_SESSION['visa_entry_id']."\r\n";
$message .= Port of Exit from Country - $_SESSION['exitpointxx']."\r\n";
$message .= Places Likely to be Visit - $_SESSION['placelikelyvisited']."\r\n";
$message .= Places Likely to be Visit2 - $_SESSION['Placelikelyvisited2']."\r\n";
$message .= Do you have Old Visa - $_SESSION['oldvisa']."\r\n";
$message .= Old Visa Number - $_SESSION['old_visa_no']."\r\n";
$message .= Old Visa Type - $_SESSION['old_visa_type_id']."\r\n";
$message .= Old Visa Issue Place - $_SESSION['oldvisaissueplace']."\r\n";
$message .= Permanent Stay  - $_SESSION['permStay']."\r\n";
$message. = Refuse Details - $_SESSION['refuse_details']."\r\n";
$message .= Country Visited - $_SESSION['country_visited']."\r\n";
$message .= Name of Referance - $_SESSION['nameofsponsor_ind']."\r\n";
$message .= Referance Address - $_SESSION['referanceaddress']."\r\n";
$message .= Referance City - $_SESSION['referancecity']."\r\n";


$to = "mailme@imgrv.in";//<== update the email address
$headers = "From: $email_from \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers,$message);
//done. redirect to thank-you page.
header('Location: thank-you.html');

?>
Gaurav Singh
  • 43
  • 2
  • 10

4 Answers4

3

use proper way concatenation for PHP code like:

$test ="abc";
echo $email_body = "You have received a new message from the user".$test."\r\n";
Rahul Prajapati
  • 426
  • 1
  • 4
  • 12
1

Add error_reporting(E_ALL); ini_set('display_errors', 1); in beginning of this file. You can see syntax error. you have wrongly added " " for concatenation.

softech
  • 356
  • 1
  • 4
  • 23
1

Try This

<?php
session_start();

$email_from = 'no-reply@indianvisaservice.org';//<== update the email address
$email_subject = "New Form submission";

$message = "Application Reference No - ".$_SESSION['appid']." \r\n";
$message .= "type of VISA Application - ".$_SESSION['visatype']."\r\n";
$message .= "Port of Arrival - ".$_SESSION['arrivalport']."\r\n";
// Concatenate all message like this
$email_body = "You have received a new message from the user". $_SESSION['givenname']."\r\nHere is the message:\n $message";


$to = "mailme@imgrv.in";//<== update the email address
$headers = "From: $email_from \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');

?>
Artier
  • 1,648
  • 2
  • 8
  • 22
0

Couple of points:

  1. Write this line below $message variable, $message is not defined yet.

    $email_body = "You have received a new message from the user ".$_SESSION['givenname']."\r\n" . "Here is the message:\n $message"; //not sure you made typo here but it should be like this. remove semicolon before dot because you are doing string concatenation.

  2. In mail function, I'm not sure why are you passing $message variable, last argument is for additional parameter Click here for more info

So it should be:

mail($to,$email_subject,$email_body,$headers);

Hope this help you.

Bhaskar Jain
  • 1,651
  • 1
  • 12
  • 20