Jump to content

?Message? not appears in emailed data


fazlionline

Recommended Posts

Hi all

 

I have this script to send form data to my email

Everything goes perfect, but there is no ?Message? text in my inbox.

I receive all information but do not receive which are written in Message text area.

 

My code is:

 

<?php 
$to = "123@yahoo.com"; 
$subject = $_REQUEST['subj'] ; 
$org = $_REQUEST['org'] ; 
$tele = $_REQUEST['tele'] ; 
$city = $_REQUEST['city'] ; 
$email = $_REQUEST['email'] ; 
$message = $_REQUEST['message'] ; 

$details = "Subject: $subject\n
           Organization: $org\n
           Telephone: $tele\n
           City: $city\n
           From: $email \n
       ";

$headers = "From: $email"; 
$sent = mail($to, $subject, $details, $headers, $message) ; 
if($sent) 
{print "Your mail was sent successfully"; }
else 
{print "We encountered an error sending your mail"; }
?>

 

 

123@yahoo.com is written just for security purpose here

need help

Edited by fazlionline
Link to comment
Share on other sites

$message = $_REQUEST['message'] ;

 

$details = "Subject: $subject\n

Organization: $org\n

Telephone: $tele\n

City: $city\n

From: $email \n

";

 

Well, if you look at your code, you aren't actually including the message in the $details variable. You need to use this instead:

 

$message = $_REQUEST['message'] ; 

$details = "Subject: $subject\n
           Organization: $org\n
           Telephone: $tele\n
           City: $city\n
           From: $email \n
           Message: $message
       ";

 

Also, minor detail, but due to security issues with $_REQUEST it is better practice to use $_POST[] rather than $_REQUEST[].

 

From php.net:

"Note: The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms and therefore could be modified by the remote user and cannot be trusted. The presence and order of variables listed in this array is defined according to the PHP variables_order configuration directive. "

http://us2.php.net/manual/en/reserved.variables.request.php

Link to comment
Share on other sites

$sent = mail($to, $subject, $details, $headers, $message) ;

 

Oops, didn't see that. If you look at the PHP manual's entry on mail() (http://us2.php.net/manual/en/function.mail.php) you'll notice that this is the standard from:

 

bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

 

You can't simply add on variables and expect PHP to understand what to do with them -- you have to follow the form that appears in the manual. Anything that you want to have appear within the message needs to included within that 3rd variable (in your case, you called it "details". In order to include $message within the email, you need to do what I specified in my first post.

Link to comment
Share on other sites

Thanks falkencreative

 

I have made that form and it works well.

Thanks for your help.

 

I upload this form to website, filled it and emails was sent to me with exact information.

Thanks a lot

 

The final code was:

 

<?php 
$to = "123@yahoo.com"; 
$subject = $_REQUEST['subj'] ;
$name = $_REQUEST['name'] ; 
$org = $_REQUEST['org'] ; 
$tele = $_REQUEST['tele'] ; 
$city = $_REQUEST['city'] ; 
$email = $_REQUEST['email'] ; 
$message = $_REQUEST['message'] ;
$url = "KGC - Contact Form"; 

$details = "\n URL - Form: $url\n
           Subject: $subject\n
           Name: $name\n
           Organization: $org\n
           Telephone: $tele\n
           City: $city\n
           From: $email \n
           Message: $message \n
       ";

$headers = "From: $email"; 
$sent = mail($to, $subject, $details, $headers, $message) ; 
if($sent) 
{print "Your mail was sent successfully"; }
else 
{print "We encountered an error sending your mail"; }
?>

 

thanks

Edited by fazlionline
Link to comment
Share on other sites

Hi

I have copied the same code to another website.

But I removed two fields form there, the organization and telephone fields.

 

I have uploaded to other site, and when I fill the form and click on submit button, I recive this error:

 

Warning: mail(): SMTP server response: 553 5.3.0 ... DISCARD Spam Relay in d:\Customers\user1092190\www\test\contactus.php on line 17

We encountered an error sending your mail

 

I think the code is correct, but this may be with website strong security or something else.

 

My code is here:

 

<?php 
$to = "123@yahoo.com"; 
$url = "EG - Contact Form"; 
$subject = $_REQUEST['subj'] ; 
$city = $_REQUEST['city'] ; 
$email = $_REQUEST['email'] ; 
$message = "Register me for Monthly Newwsletter" ; 

$details = "URL - Form: $url\n
           Subject: $subject\n
           City: $city\n
           From: $email \n
           Message: $message \n
       ";

$headers = "From: $email"; 
$sent = mail($to, $subject, $details, $headers, $message) ; 
if($sent) 
{print "You are successfully added to our monthly newsletter"; }
else 
{print "We encountered an error sending your mail"; }
?>

Link to comment
Share on other sites

The "From" header needs an address that the Mail Server does not consider to be Spam.

I should be an email address from the Domain the Server recognizes. Although the message may be sent from your site, if the from header says it is coming from me@jlhaslip.com and the domain name jlhaslip.com is not hosted there, the Mail server will consider it a Spam email.

Try the form using a valid email address.

 

The Email address the user supplies should be part of the message, not a Mail Header.

 

*edit*

 

The From Header needs to be the Domain's Email address.

Edited by jlhaslip
Link to comment
Share on other sites

The "From" header needs an address that the Mail Server does not consider to be Spam.

I should be an email address from the Domain the Server recognizes. Although the message may be sent from your site, if the from header says it is coming from me@jlhaslip.com and the domain name jlhaslip.com is not hosted there, the Mail server will consider it a Spam email.

 

how can i fix this problem?

 

is script in the following code is wrong?

 

$email = $_REQUEST['email'] ; 

$headers = "From: $email"; 

 

or i sould change the code here

Link to comment
Share on other sites

If I understand it correctly, @jlhaslip is saying that this line:

 

$headers = "From: $email"; 

 

is incorrect. Since this message is coming from a website, not directly from that person's email address, your server is giving you an error. Include $email within the $message variable instead, and in the $header variable, set the "from" address to be an email address that has the same domain as the website the form is in.

Link to comment
Share on other sites

i made an email on my domain, like real_email@mydomain.com

then sit the follwoing code:

 

<?php 
$to = "123@yahoo.com"; 
$subject = $_REQUEST['subj'] ;
$name = $_REQUEST['name'] ; 
$city = $_REQUEST['city'] ; 
$email = $_REQUEST['email'] ; 
$message = $_REQUEST['message'] ;
$url = "EG - Contact Form"; 

$details = "\n URL - Form: $url\n
           Subject: $subject\n
           Name: $name\n
           City: $city\n
           From: $email \n
           Message: $message \n
       ";

$headers = "real_email@mydomain.com"; 
$sent = mail($to, $subject, $details, $headers, $message) ; 
if($sent) 
{print "Your mail was sent successfully"; }
else 
{print "We encountered an error sending your mail"; }
?> 

 

but i still get error

Edited by fazlionline
Link to comment
Share on other sites

i have solved this problem and got a new code while googling

...
$email = $_REQUEST['email'] ; 
ini_set("sendmail_from", $email);
$headers = $email; 
$sent = mail($to, $subject, $details, $headers, $message) ; 
...

this code solve the problem and i can resive the email in my yahoo inbox.

 

but one thing i was so confused with:

 

the same code i posted at first on this topic, i used it in other site.

it was working there directly.

 

but in second site, this have pasted same code and i solve it with this new lines in my code.

 

i do not know y

Link to comment
Share on other sites

but some one told me that you can go to your control panel and make changes there.

then you will past the simplist mail () script and it will work.

 

will any one tell me where can i make changes?

 

I don't believe there is one consistent way to do things, since different hosts have different settings, and may offer different control panels. In most cases, the web host gives no direct access to the PHPini file, which is why you may have to do the "ini_set("sendmail_from", $email);" workaround.

Link to comment
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...