Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

trying to send email but getting unexpected t_variable

the mail() function

Moderators: macek, egami, gesf

trying to send email but getting unexpected t_variable

Postby zsalloum » Sun Feb 26, 2012 2:05 am

i am trying to send an email with a simple script but I'm getting an unexpected t_variable error and i checked the code multiple of times but i didn't find the error...i would appreciate it if you help me!
here's the code

<?php
if(isset($_POST['email'])) {
$time = "unchecked";
$selected_radio = $_POST['when'];
if ($selected_radio == "flexible") {
$time = "flexible";
}
elseif ($selected_radio == "hour") {
$time = "within the hour";
}
elseif ($selected_radio == "date") {
$time = "at a specific date";
}
$where = $_POST['addressField'];
$remote_check_box = $_POST['remoteCheckBox'];
    $comments = $_POST['needTextArea'];
  $who = $_POST['helpNeeded'];

    $email_message = "Form details below.\n\n";
     
    }
     
    $email_message .= "Who do you need: ".$who."\n";
    $email_message .= "When should they start ".$time."\n";
    $email_message .= "Where: ".$where." \n";
    $email_message .= "Job can be performed remotely: ".$remote_check_box."\n";
    $email_message .= "Comments: ".$comments."\n";
     
     

$headers = 'From: webmaster@fanara.co' . "\r\n" .
'Reply-To: webmaster@fanara.co' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$email_to = "zsalloum@aucegypt.edu";  
$email_subject = "request a service";

mail($emailto, $emailsubject, $email_message, $headers); 
?>
 
<!-- include your own success html here -->
 
Thank you for contacting us. We will be in touch with you very soon.
 
<?php
}
?>
zsalloum
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Feb 26, 2012 1:56 am

Re: trying to send email but getting unexpected t_variable

Postby rupali » Sun Feb 26, 2012 6:55 pm

hello,

in mail function the name of variables are not correct you have missed underscore in to and subject variables, so correct with the below one :
mail($email_to, $email_subject, $email_message, $headers);
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: trying to send email but getting unexpected t_variable

Postby zsalloum » Mon Feb 27, 2012 1:57 am

you're right thanks :D i hope that solves it!
zsalloum
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Feb 26, 2012 1:56 am

Re: trying to send email but getting unexpected t_variable

Postby zsalloum » Mon Feb 27, 2012 2:06 am

now it's giving me an error on line 21 which is
Code: Select all
    $email_message = "Who do you need: " . $who_is_needed;

i really don't know what's wrong with this syntax
i appreciate your support

Code: Select all
<?php
if(isset($_POST['email'])) {
   $who_is_needed = $_POST['helpNeeded'];
   $time = "unchecked";
   $selected_radio = $_POST['when'];
   if ($selected_radio == "flexible") {
      $time = "flexible";
   }
   elseif ($selected_radio == "hour") {
      $time = "within the hour";
   }
   elseif ($selected_radio == "date") {
      $time = "at a specific date";
   }
   $where = $_POST['addressField'];
   if(isset($_POST['remoteCheckBox'])){
      $remote_check_box = "Yes";
      }
      $comments = filter_input(INPUT_POST, 'needTextArea', FILTER_SANITIZE_ENCODED);

    $email_message = "Who do you need: " . $who_is_needed;
    $email_message .= "\r\n When should they start: " . $time;
    $email_message .= "\r\n Where: " . $where;
    $email_message .= "\r\n Job can be performed remotely: " . $remote_check_box;
    $email_message .= "\r\n Comments: " . $comments;
     
     

   $headers = 'From: webmaster@fanara.co' . "\r\n" .
      'Reply-To: webmaster@fanara.co' . "\r\n" .
      'X-Mailer: PHP/' . phpversion();
   $email_to = "zsalloum@aucegypt.edu";  
   $email_subject = "request a service";

   mail($email_to, $email_subject, $email_message, $headers); 
?>
 
<!-- include your own success html here -->
 
Thank you for contacting us. We will be in touch with you very soon.
 
<?php
}
?>
zsalloum
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Feb 26, 2012 1:56 am

Re: trying to send email but getting unexpected t_variable

Postby rupali » Mon Feb 27, 2012 6:30 pm

hello,

There is no error !!!

i have tested your script on my system as well and no error in that line, the syntax of if statement is not correct may be because of that, this is not executing, you have missed the else statement after two else if's.
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron