By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

Email Problem using PHP

P: 16
I am attempting to send and email via my feedback form and nothing seems to go thru. I have tried sending to a yahoo account and a gmail account. I have changed a few things in my script several times and did receive a couple emails about 1 day later that just went into bulk. As of now I receive nothing. Can someone please take a look at my script and tell me what I am doing wrong. Also how do I prevent mails from going to bulk/spam? Could this be an issue with my web hosting company ?

Form.php
[php]
<form method="post" action="sendfeedback.php">
<div align="center">
<p align="center"><font face='Verdana' >Contact Us</font> </p>
<p>Feedback<br>
<textarea name="message" rows="5" cols="50"></textarea></p>
<p>Your Email:
<input name="email" type="text" /></p>
<p><input type="submit" value="Send Feedback" /></p>
</div>
</form>


SendFeedback.php

<?php

//get the senders email

$from = $_REQUEST['email'] ;

//define the receiver of the email

$to = 'support@mysite.com';

// subject of the email

$subject = 'Feedback Form Results';

//define the message to be sent.

$message = $_REQUEST['message'] ;

//define the headers

$headers = "From: '$from'\r\nReply-To: '$from' ";

//send the email

$mail_sent = @mail( $to, $subject, $message, $headers );

echo $mail_sent ? "<br><font face='Verdana' size='3' color='green'>Mail sent, Thank You for your Feedback</font>" : "<br><font face='Verdana' size='3' color='green'>Mail failed</font>";

?>[/php]
Feb 20 '08 #1
Share this Question
Share on Google+
11 Replies


nomad
Expert 100+
P: 664
I am attempting to send and email via my feedback form and nothing seems to go thru. I have tried sending to a yahoo account and a gmail account. I have changed a few things in my script several times and did receive a couple emails about 1 day later that just went into bulk. As of now I receive nothing. Can someone please take a look at my script and tell me what I am doing wrong. Also how do I prevent mails from going to bulk/spam? Could this be an issue with my web hosting company ?

Form.php

<form method="post" action="sendfeedback.php">
<div align="center">
<p align="center"><font face='Verdana' >Contact Us</font> </p>
<p>Feedback<br>
<textarea name="message" rows="5" cols="50"></textarea></p>
<p>Your Email:
<input name="email" type="text" /></p>
<p><input type="submit" value="Send Feedback" /></p>
</div>
</form>


SendFeedback.php

<?php

//get the senders email

$from = $_REQUEST['email'] ;

//define the receiver of the email

$to = 'support@mysite.com';

// subject of the email

$subject = 'Feedback Form Results';

//define the message to be sent.

$message = $_REQUEST['message'] ;

//define the headers

$headers = "From: '$from'\r\nReply-To: '$from' ";

//send the email

$mail_sent = @mail( $to, $subject, $message, $headers );

echo $mail_sent ? "<br><font face='Verdana' size='3' color='green'>Mail sent, Thank You for your Feedback</font>" : "<br><font face='Verdana' size='3' color='green'>Mail failed</font>";

?>
This is not right.
$to = 'support@mysite.com';
$subject = 'Feedback Form Results';

try this instead
$EmailTo = "support@mysite.com";
$subject = "Feedback Form Results";

then
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");


nomad
ps I think
echo $mail_sent ? statement is wrong to....
Feb 20 '08 #2

ronverdonk
Expert 2.5K+
P: 4,258
Next time enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

moderator
Feb 20 '08 #3

P: 16
Tried what you gave me. Still no email. Any other suggestions are appreciated.
Feb 20 '08 #4

nomad
Expert 100+
P: 664
I am attempting to send and email via my feedback form and nothing seems to go thru. I have tried sending to a yahoo account and a gmail account. I have changed a few things in my script several times and did receive a couple emails about 1 day later that just went into bulk. As of now I receive nothing. Can someone please take a look at my script and tell me what I am doing wrong. Also how do I prevent mails from going to bulk/spam? Could this be an issue with my web hosting company ?

Form.php
[php]
<form method="post" action="sendfeedback.php">
<div align="center">
<p align="center"><font face='Verdana' >Contact Us</font> </p>
<p>Feedback<br>
<textarea name="message" rows="5" cols="50"></textarea></p>
<p>Your Email:
<input name="email" type="text" /></p>
<p><input type="submit" value="Send Feedback" /></p>
</div>
</form>


SendFeedback.php

<?php

//get the senders email

$from = $_REQUEST['email'] ;

//define the receiver of the email

$to = 'support@mysite.com';

// subject of the email

$subject = 'Feedback Form Results';

//define the message to be sent.

$message = $_REQUEST['message'] ;

//define the headers

$headers = "From: '$from'\r\nReply-To: '$from' ";

//send the email

$mail_sent = @mail( $to, $subject, $message, $headers );

echo $mail_sent ? "<br><font face='Verdana' size='3' color='green'>Mail sent, Thank You for your Feedback</font>" : "<br><font face='Verdana' size='3' color='green'>Mail failed</font>";

?>[/php]
Not sure if php is case-senative
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="sendfeedback.php">
change to
Expand|Select|Wrap|Line Numbers
  1.  <form method="POST" action="SendFeedback.php">
this might be wrong
Expand|Select|Wrap|Line Numbers
  1. <input type="submit" value="Send Feedback" />
try this
Expand|Select|Wrap|Line Numbers
  1. <input type="submit" name="submit" value="Submit">
you might want to add this section after you posted data into local variables.
Expand|Select|Wrap|Line Numbers
  1. // validation
  2. $validationOK=true;
  3. if (!$validationOK) {
  4.   print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  5.   exit;
  6. }
Which brings up at matter you have no $_POST sections.



still not to sure about this part
echo $mail_sent ? "<br><font face='Verdana' size='3' color='green'>Mail sent, Thank You for your Feedback</font>" : "<br><font face='Verdana' size='3' color='green'>Mail failed</font>";


nomad
Feb 20 '08 #5

P: 16
I contacted my web hosting company and their is a piece of code they gave me that has to be inserted before the mail( ) function. Wish I knew this before. Thanks for your help ! It is working now.
Feb 20 '08 #6

nomad
Expert 100+
P: 664
I contacted my web hosting company and their is a piece of code they gave me that has to be inserted before the mail( ) function. Wish I knew this before. Thanks for your help ! It is working now.

Good job...
if you wish to share that info it might help others that might have the same problem

nomad
Feb 20 '08 #7

P: 65
I contacted my web hosting company and their is a piece of code they gave me that has to be inserted before the mail( ) function. Wish I knew this before. Thanks for your help ! It is working now.
Hi phpmind,

Could u please send me the piece of code given by the web hosting company?
I'm also having the same problem.......
Plz... help me out....

Thanx n Regards
Yas
Feb 21 '08 #8

P: 16
I was told to insert this code right before the mail () function is executed.

Where 'user@domain.com' should be a valid email address associated with the domain name for example (postmaster@mysite.com)

//initialize mail function for web host
<? ini_set('sendmail_from', 'user@domain.com' ); ?>

Hope this helps!
Feb 21 '08 #9

P: 65
I was told to insert this code right before the mail () function is executed.

Where 'user@domain.com' should be a valid email address associated with the domain name for example (postmaster@mysite.com)

//initialize mail function for web host
<? ini_set('sendmail_from', 'user@domain.com' ); ?>

Hope this helps!

Hi,
Thanx 4 ur reply.

But i'm not sure where to put this code.
Where it should be present whether 'sendfeedback.php' or 'feedback.html'?
What is meant by 'sendmail_from'?

I put it in sendfeedback.php, but the same thing is happened again.(I got the message "Mail Failed" as output.)

Could you please explain...??

Thanx n Regards
Yas
Feb 22 '08 #10

Markus
Expert 5K+
P: 6,050
Hi,
Thanx 4 ur reply.

But i'm not sure where to put this code.
Where it should be present whether 'sendfeedback.php' or 'feedback.html'?
What is meant by 'sendmail_from'?

I put it in sendfeedback.php, but the same thing is happened again.(I got the message "Mail Failed" as output.)

Could you please explain...??

Thanx n Regards
Yas
This is because it's relative to only the OP's (original poster) server.

You might not be running the same PHP.
Feb 22 '08 #11

P: 16
This code would go directly before your mail() function. As the last post states it may be different for your web server/php environment. If you continue to have problem I would suggest contacting your service provider if all else fails.
Feb 22 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.