contact form

Hi All,

i have a simple contact form with name, company, telephone, email and message
i want to email it across to my email address but its giving me an email but when i test my code online with php tester it works fine.

am i missing something!!!!!!!

i have attached the php code and error

error is
Parse error: syntax error, unexpected '~' in /data/22/2/92/133/2092785/user/2294727/htdocs/mailer.php on line 70
if(isset($_POST['submit'])) {
$to = "myemail@myemail.com";
$subject = "This is an automated message from System.";
$name_field = $_POST['name'];
$company_field = $_POST('company');
$telephone_field = $_POST('telephone');
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n Company: $company_field\n Telephone: $telephone_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Message has been send to $to!";
mail($to, $subject, $body);
} else {
echo "Your message has not been sent";
}

Open in new window

ammartahir1978Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
The error is reported on line 70.  We have a code snippet here with only 16 lines.  Please post the entire code so we can see all of the line numbers. thanks.
0
ammartahir1978Author Commented:
hi Ray, thats the problem i have only this code!!!! shall i post the form design as well if that helps?
0
Jagadishwor DulalBraces MediaCommented:
Got your error check your code:
$company_field = $_POST('company'); //used ('company') () bracket instead of []
$telephone_field = $_POST('telephone');/used ('telephone') () bracket instead of []

Open in new window

They seems like functions

must be
$company_field = $_POST['company'];
$telephone_field = $_POST['telephone'];

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

kumaranmcaCommented:
Greetings Ammartahir,

Currently you put the code no issues. Its working perfectly.
 
I think'~' added in your code. Please delete and try your code..Its work for you
Parse error: syntax error, unexpected '~'

Thanks & Regards,
Kumaran
0
ammartahir1978Author Commented:
hi Jag i still do get what the error is.

Hi Kumaran there is no ~ in my code thats the whole code which i posted here.
0
kumaranmcaCommented:
Hi ammartahir,

Okay, Can you attach your php file with thread...I will review and get back to you. Because you getting error display on line 70. But you posted program code only 16 lines.
0
ammartahir1978Author Commented:
hi kumaran, this is the whole file, i used only this code in my php
mailer.php
0
Jagadishwor DulalBraces MediaCommented:
YOur file is corrupted post it on txt extension.
0
ammartahir1978Author Commented:
here you go Jag mailer.txt
0
Jagadishwor DulalBraces MediaCommented:
Post your form code also here
0
Jagadishwor DulalBraces MediaCommented:
Still there was mistake try using this code if possible post your form code also.

<?php
if(isset($_POST['submit'])) {
$to = "myemailaddress";
$subject = "This is an automated message from System.";
$name_field = $_POST['name'];
$company_field = $_POST['company'];
$telephone_field = $_POST['telephone'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n Company: $company_field\n Telephone: $telephone_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Message has been send to $to!";
mail($to, $subject, $body);
} else {
echo "Your message has not been sent";
}
?>

Open in new window

0
ammartahir1978Author Commented:
now its saying unexpected ?

form code attached
<form method="post" action="mailer.php">
											<table  cellspacing="0" cellpadding="0" class="form">
											  <tr>
												<td  style="width:198px; height:128px">
													<table  cellspacing="0" cellpadding="0">
													  <tr>
														<td  style="width:198px; height:27px"><input name="name" type="text" value="your name:"></td>
													  </tr>
													   <tr>
														<td  style="width:198px; height:27px"><input name="company" type="text" value="your company:"></td>
													  </tr>
													   <tr>
														<td  style="width:198px; height:27px"><input name="telephone" type="text" value="telephone:"></td>
													  </tr>
													   <tr>
														<td  style="width:198px; height:27px"><input name="email" type="text" value="e-mail"></td>
													  </tr>
													</table>
												</td>
												<td  style="width:202px; height:128px">
													<table  cellspacing="0" cellpadding="0">
													  <tr>
														<td  style="width:202px; height:109px"><textarea name="message" cols="0" rows="0">message:</textarea></td>
													  </tr>
													  <tr>
														<td  style="width:202px; height:19px">
														<br style="line-height:1px">
														<img src="images/spacer.gif" alt="" width="116" height="1"><strong><input type="reset" value="reset" name="reset"</strong>
                                                        <img src="images/spacer.gif" alt="" width="15" height="1"><strong><input type="submit" value="Submit" name="submit"</strong>		</td>
													  </tr>
													</table>
												</td>
											  </tr>
											</table>
											</form>

Open in new window

0
Ray PaseurCommented:
When there is a parse error with "unexpected" it usually means that somewhere earlier in the script there was a missing terminator - perhaps missing a right paren, or a semicolon.  But that said, if there is an error reported on line 70 and you only have 16 (or 18) lines of code, you are not running the script we are looking at here.  The script you are running has at least 70 lines of code.  There may be an error in the paths to the script you are testing.  Programmers commonly use "signal" notices to visualize information about their scripts.  For example, you might make the script write its name in the browser output with something like this:

echo $_SERVER["REQUEST_URI"];

But that aside, try installing this version of the script (make the modifications that make sense for use in your environment).  If this script runs without errors, check your inbox and spam folder.  If there is still no message found, you will want to work with your server administrator to ensure that the server has the mail functions enabled.  The PHP.net web site may be helpful - definitely worth reading carefully!
http://us.php.net/manual/en/book.mail.php

Best of luck with it, ~Ray
<?php // RAY_form_to_email.php
error_reporting(E_ALL);


// SEND MAIL FROM A FORM


// REQUIRED VALUES ARE PREPOPULATED - CHANGE THESE FOR YOUR WORK
$from  = "NoReply@Your.org";
$subj  = "Contact Form";

// THIS IS AN ARRAY OF RECIPIENTS - CHANGE THESE FOR YOUR WORK
$to[]  = "You@Your.org";
$to[]  = "Her@Your.org";
$to[]  = "Him@Your.org";



// IF THE DATA HAS BEEN POSTED
if (!empty($_POST['email']))
{
    // CLEAN UP THE POTENTIALLY BAD AND DANGEROUS DATA
    $email      = clean_string($_POST["email"]);
    $name       = clean_string($_POST["name"]);
    $telephone  = clean_string($_POST["telephone"]);

    // CONSTRUCT THE MESSAGE THROUGH STRING CONCATENATION
    $content    = NULL;
    $content   .= "You have a New Query From $name" . PHP_EOL . PHP_EOL;
    $content   .= "Tel No: $telephone" . PHP_EOL;
    $content   .= "Email: $email" . PHP_EOL;

    // SEND MAIL TO EACH RECIPIENT
    foreach ($to as $recipient)
    {
        if (!mail( $recipient, $subj, $content, "From: $from\r\n"))
        {
            echo "MAIL FAILED FOR $recipient";
        }
        else
        {
            echo "MAIL WORKED FOR $recipient";
        }
    }
}


// A FORM TO TAKE CLIENT INPUT FOR THIS SCRIPT
$form = <<<ENDFORM
<form method="post">
Please enter your contact information
<br/>Email: <input name="email" />
<br/>Phone: <input name="telephone" />
<br/>Name:  <input name="name" />
<br/><input type="submit" />
</form>
ENDFORM;

echo $form;



// A FUNCTION TO CLEAN UP THE DATA - AVOID BECOMING AN OPEN-RELAY FOR SPAM
function clean_string($str)
{
    // IF MAGIC QUOTES IS ON, WE NEED TO REMOVE SLASHES
    $str = stripslashes($str);

    // REMOVE EXCESS WHITESPACE
    $rgx
    = '#'                // REGEX DELIMITER
    . '\s'               // MATCH THE WHITESPACE CHARACTER(S)
    . '\s+'              // MORE THAN ONE CONTIGUOUS INSTANCE OF WHITESPACE
    . '#'                // REGEX DELIMITER
    ;
    $str = preg_replace($rgx, ' ', $str);

    // REMOVE UNWANTED CHARACTERS
    $rgx
    = '#'                // REGEX DELIMITER
    . '['                // START OF A CHARACTER CLASS
    . '^'                // NEGATION - MATCH NONE OF THE CHARACTERS IN THIS CLASS
    . 'A-Z0-9'           // KEEP LETTERS AND NUMBERS
    . '&+:?_.,/\-'       // KEEP SOME SPECIAL CHARACTERS (ESCAPED HYPHEN)
    . ' '                // KEEP BLANKS
    . ']'                // END OF THE CHARACTER CLASS
    . '#'                // REGEX DELIMITER
    . 'i'                // CASE-INSENSITIVE
    ;
    $str = preg_replace($rgx, NULL, $str);

    return trim($str);
}

Open in new window

0
ammartahir1978Author Commented:
hi ray thank you for your post can you please let me know what parts i need to change according to my script because that all i want to receive in my email????
0
ammartahir1978Author Commented:
Is there anything can be done?
0
ammartahir1978Author Commented:
Hi. Been a few days, thinking of abandoning.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ammartahir1978Author Commented:
hello
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.