Jump to content
Stef's Coding Community
fazlionline

problem with PHP Mail ();

Recommended Posts

Hi All

I have a form: http://www.fazlionline.com/school/send_email_03.php

I want if anyone fill this form and press the button, the given information should be sent to me.

But it not works

 

Parse error: syntax error, unexpected '@' in E:\inetpub\vhosts\fazlionline.com\httpdocs\school\send_email_03.php on line 2

 

Can anyone help me?

!!!I want my script so simple!!!

Is there anything needed.

Thanks

Share this post


Link to post
Share on other sites

The mail function needs a minimum of 3 parameters.

To, Subject and Message are required, Additional headers and Parameters are optional, although the From header is suggested to avoid becoming Spam.

 

$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

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

 

 

http://ca.php.net/manual/en/function.mail.php

Share this post


Link to post
Share on other sites

Thanks Dear

This was successful

But have TWO problems:

 

 

1. When I go to this page, an email is automatically sent to my inbox.

2. I write the email address in ?Email? box, but it not appears in the email received, it just says ?From: "$_POST@yahoo.com" <$_POST@yahoo.com>".

3. Is sending emails direct to inbox is safe.

 

Please check http://www.fazlionline.com/school/send_email_01.php again

Thanks

Share this post


Link to post
Share on other sites

1. When I go to this page, an email is automatically sent to my inbox.

here i would use the conditional statement after you validate all the user input, for example:

 

if($_POST['button']){

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

}

 

this way it only sends the message when you push the send button

 

2. I write the email address in ?Email? box, but it not appears in the email received, it just says ?From: "$_POST@yahoo.com" <$_POST@yahoo.com>".

 

and here what i would do is put the

elements into the html. such as

and then assign the user input in email the the variable $email like this

 

 

$email=$_POST['email'];

 

$to = 'nobody@example.com';

$subject = 'the subject';

$message = 'hello';

$headers = "From: $email" . "\r\n" .

'Reply-To: webmaster@example.com' . "\r\n" .

'X-Mailer: PHP/' . phpversion();

Share this post


Link to post
Share on other sites

I made the changes as you told, but it still give error.

At this time, no email is sent to my inbox.

 

My new code is:

 

<?php

if($_POST['button']){
mail($to, $subject, $message, $headers);
}

$email=$_POST['email'];

$to      = $_POST['email'];
$subject = $_POST['name'];
$message = $_POST['message'];
$headers = "From: $email" . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

?>

 

The error I receive is:

 

Warning: mail() [function.mail]: SMTP server response: 503 Bad sequence of commands. You must specify the recipients of a message before you can send it in E:\inetpub\vhosts\fazlionline.com\httpdocs\school\send_email_01.php on line 4

 

What is the solution?

 

check it here: http://www.fazlionline.com/school/send_email_01.php

Edited by fazlionline

Share this post


Link to post
Share on other sites

Send us your feed back:


 

<?php

 

if ($_POST && isset($missing) && !empty($missing)) {

?>

Please complete the missing item(s) indicated.

<?php

}

elseif ($_POST && $mailsent = false) {

?>

Sorry, there was a problem sending your message.

Please try later.

<?php

}

elseif ($_POST && $mailsent = true) {

?>

 

Your message has been sent. Thank you for your feedback.

<?php } ?>

 

 

Name:

<?php if(isset($missing) && in_array('name', $missing)) { ?> :Please enter your name <?php }?>

 

Email:

<?php if(isset($missing) && in_array('email', $missing)) { ?> :Please enter your email <?php }?>

Message:

<?php if(isset($missing) && in_array('message', $missing)) { ?> Please enter your Message: <?php }?>

<?php

if (isset($missing)) {

echo htmlentities($_POST['message']);

} ?>

 

Share this post


Link to post
Share on other sites

hello cugopob.vlad

i tried your code, is too lengthyit and gives error,

 

Method Not Allowed

The HTTP verb used to access this page is not allowed.

 

see it here: http://www.fazlionline.com/school/killer01.html

 

 

I liked jlhaslip's Script

hi jlhaslip, will u plz help me just to add one field for email only!!!

 

or see the form agian:

http://www.fazlionline.com/school/email01.html

 

 

Thansk

Edited by fazlionline

Share this post


Link to post
Share on other sites
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$message .= "\r\n";
$message .= $_POST['uremail'];
$message .= "\r\n";
$message .= 'End message';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...