Jump to content

Recommended Posts

Ok im making this script. its a survey that when u hit submit it will show your answers on another page then email the results to me. ok so far i have it working where it will display the answers on another page but it wont email the answers to me. and the page that shows the answers doesnt put each question on a separte line... Im 85% there, i just need help!
[b]
This is the php page[/b]
[code]
<form method="post" action="sendeail.php">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
<table width="500">
<tr>
<td width="319"><label><span class="style1">How often do you visit MOSI?</span></label></td>
</tr>
<tr>
<td><span class="style5">
<input type="radio" name="Q1" value="First visit">
First visit</span></td>
</tr>
<tr>
<td><span class="style5">
<label>
<input type="radio" name="Q1" value="Less than once a year">
Less than once a year</label>
</span></td>
</tr>
<tr>
<td><span class="style5">
<label>
<input type="radio" name="Q1" value="About once a year">
About once a year</label>
</span></td>
</tr>
<tr>
<td><span class="style5">
<label>
<input type="radio" name="Q1" value="More than once a year">
More than once a year</label>
</span></td>
</tr>
</table>
<br>
<p align="left" class="style1">
<label></label>
</p>
<table width="500">
<tr>
<td><label><span class="style1">How often do you visit museums in general?</span></label></td>
</tr>
<tr>
<td><input type="radio" name="Q2" value="Less than once a year">
Less than once a year</td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q2" value="About once a year">
About once a year</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q2" value="A few times a year">
A few times a year</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q2" value="Once a month or more">
Once a month or more</label></td>
</tr>
</table>
<br>
<table width="500">
<tr>
<td><label>What is your gender? </label></td>
</tr>
<tr>
<td><input type="radio" name="Q3" value="Male">
Male</td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q3" value="Female">
Female</label></td>
</tr>
</table>
<br>
<table width="500">
<tr>
<td><label>What is your age group? </label></td>
</tr>
<tr>
<td><input type="radio" name="Q4" value="15-24">
15-24</td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q4" value="25-34">
25-34</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q4" value="35-54">
35-54</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q4" value="55-64">
55-64</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q4" value="65 and over">
65 and over</label></td>
</tr>
</table>
<p align="left" class="style1">  </p>
<table width="500">
<tr>
<td><label>Do you currently live in Tampa? </label></td>
</tr>
<tr>
<td><input type="radio" name="Q5" value="Yes">
Yes</td>
</tr>
<tr>
<td><label>
<input type="radio" name="Q5" value="No">
No</label></td>
</tr>
</table>
<p align="left" class="style1">Including yourself, how many persons are there in your group or family visiting the museum with you today?<br>
<label>
<select name="Q6" size="1">
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6 or more</option>
</select>
</label>
</p>
<p align="left" class="style1">How many of those are aged 12 or older, again, including yourself?<br>
<label>
<select name="Q7">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6 or more</option>
</select>
</label>
</p>

Your Email:<br />
<input type="text" name="visitormail" size="35" />
<br />
<br />
<br />
Mail Message: <br />
<textarea name="notes" rows="4" cols="40"></textarea>
<br />
<input type="submit" value="Send Mail" />
</form>[/code][color=#FF0000]


This is the redirected page[code]
<?php

$ip = $_SERVER['REMOTE_ADDR'];
$httpref = $_SERVER['HTTP_REFERER'];
$httpagent = $_SERVER['HTTP_USER_AGENT'];

$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];



$myemail = "erinkuzma@yahoo.com";

// This is a true regex check for a valid email
if (!preg_match("/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/", $_POST['visitormail'])) {
   echo "<h2>Use Back - Enter valid e-mail</h2>\n";
   $dontsend = true;
}

if (empty($visitormail) || empty($_POST['notes'])) {
   echo "<h2>Use Back - fill in all fields</h2>\n";
   $dontsend = true;
}


if ($dontsend) {
   echo "<h2>Feedback was NOT submitted</h2>\n";
   die();
}

$todayis = date("l, F j, Y, g:i a");

$attn = $attn;
$subject = $attn;

$notes = (get_magic_quotes_gpc()) ? stripslashes($_POST['notes']) : $_POST['notes'];

$message = " $todayis [EST] \r\n
Attention: $attn \r\n
Message: $notes \r\n
From: $visitor ($visitormail) \r\n";


$question = "How often do you visit MOSI? $_POST[Q1] \n";
$question .= "How often do you visit museums in general? $_POST[Q2] \n";
$question .= "What is your gender? $_POST[Q3] \n";
$question .= "What is your age group? $_POST[Q4] \n";
$question .= "Do you currently live in Tampa? $_POST[Q5] \n";
$question .= "Including yourself, how many persons are there in your group or family visiting the museum with you today? $POST[Q6] \n";
$question .= "How many of those are aged 12 or over, again, including yourself? $_POST[Q7]\n";

$headers = "From: $visitor <$visitormail> \n";

if (!empty($myemail)) {
   if (mail($myemail, $subject, $message . $question, $headers)) {
      echo 'Email sent';
   } else {
      echo 'Error sending email';
   }
}

?>

<p align="left" class="style1">
<strong>Date:</strong> <?php echo $todayis ?>
<br />
<strong>Thank You :</strong> ( <?php echo $visitormail; ?> )
<br />

<br />
<strong>Message:</strong><br />
<br><?php echo nl2br($notesout); ?></br>

<br><?php echo $question . '<br /><br />' . $ip;?></br>[/code][b]
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/
Share on other sites

Add this line:
[code]$message .= $question;[/code]
Right before:
[code]$headers = "From: $visitor <$visitormail> \n";[/code]

And the question shall be sent with the message.
About putting each question in a separate line, you can:

Change this line:
[code]<br><?php echo $question . '<br /><br />' . $ip;?></br>[/code]
To:
[code]<br><?php echo nl2br($question) . '<br /><br />' . $ip;?></br>[/code]
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43035
Share on other sites

This might be no related to the script. Are you sure PHP will send scripts at all? What happens when you try to (what messages appear?)

Check this topic:
[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95326\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95326[/a]
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43151
Share on other sites

[!--quoteo(post=381359:date=Jun 8 2006, 09:37 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 8 2006, 09:37 AM) [snapback]381359[/snapback][/div][div class=\'quotemain\'][!--quotec--]
This might be no related to the script. Are you sure PHP will send scripts at all? What happens when you try to (what messages appear?)

Check this topic:
[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95326\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95326[/a]
[/quote]



i was getting the email before! and thats when i wasnt getting the question on the redirected page. so i have gotten it. im getting a message at the top saying error sending email

[a href=\"http://mosi.org/Test/WhatDoYouThink.php\" target=\"_blank\"]http://mosi.org/Test/WhatDoYouThink.php[/a]


thats the page
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43155
Share on other sites

Something I like to do before sending the mail (for debugging purposes)
is I echo all the email info.

I echo the headers, the subject, and body.

To make sure that everything is properly placed. Do you remember what you added/changed after you were able to succesfully send an email?
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43163
Share on other sites

This is how I do my headers:

[code]
$HEADERS = "MINE-Version: 1.0\r\n";
$HEADERS .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$HEADERS .= "To: {$email}\r\n";
$HEADERS .= "From: Website <support@mydomain.com> \r\n";
[/code]

Though it sets up for HTML mail messages. But I have the to, from and sometimes CC in the header.

Then I do:
[code]
if (mail(NULL, $SUBJECT, $MESSAGE, $HEADERS)) {
   //Msg sent
} else {
   // Msg not sent
}
[/code]

I also always put { curly braces } around my variables when I have encased strings in double quotes:
[code]
echo "This is my string it is {$count} characters long";
[/code]
Helps me see and troubleshoot variables a bit better
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43172
Share on other sites

Hehe sorry, let me see...

Change these lines:
[code]
$myemail = "erinkuzma@yahoo.com";

$headers = "From: $visitor <$visitormail> \n";
[/code]

To
[code]
$headers = "MINE-Version: 1.0\r\n";
$headers.= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: Erin <erinkuzma@yahoo.com>\r\n";
$headers .= "From: {$visitor} <{$visitormail}>\r\n";
[/code]

You can then add your $message and $questions as one:
[code]
$message = " {$todayis} [EST] \r\n
      Attention: {$attn} \r\n
      Message: {$notes} \r\n
      From: {$visitor} ({$visitormail}) \r\n";
      \r\n
      How often do you visit MOSI? {$_POST['Q1']} \r\n
      How often do you visit museums in general? {$_POST['Q2']} \r\n
      What is your gender? {$_POST['Q3']}  \r\n
      What is your age group? {$_POST['Q4]'}  \r\n
      Do you currently live in Tampa? {$_POST['Q5']}  \r\n
      Including yourself, how many persons are there in your group or family visiting the museum with you today? {$POST['Q6']} \r\n
        How many of those are aged 12 or over, again, including yourself? $_POST['Q7'] \r\n";

if (mail(NULL, $subject, $message, $headers)) {
  echo "Mail sent succesfully";
} else {
  echo "Mail not sent";
}
[/code]

The \r\n are line breaks for the email message.



Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43183
Share on other sites

phpPrincess,

Just for future reference, please use a descriptive thread title and do NOT use all CAPS. Also, whining and complaining and pushing people to do your work immediately are not ways to get your question answered. Many people here will ignore you for less than that.

Take a deep breath and chill out. I'm also renaming your thread.
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43188
Share on other sites

[!--quoteo(post=381393:date=Jun 8 2006, 07:09 AM:name=phpPrincess)--][div class=\'quotetop\']QUOTE(phpPrincess @ Jun 8 2006, 07:09 AM) [snapback]381393[/snapback][/div][div class=\'quotemain\'][!--quotec--]
WHERES poirot???
[/quote]
I'm here lol [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

Frankly I don't what is the problem, because there is not much you can do wrong so mail() returns false even when the correct arguments are being used. I would try to:

1. Send to another email
2. Check if, due to a server problem, PHP stopped sending emails suddenly (check my previous post)
3. Debug it, following Sharkbait's suggestions.
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43194
Share on other sites

Damages?? [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]

i took out the combination of the message and question

[code]<?php

$ip = $_SERVER['REMOTE_ADDR'];
$httpref = $_SERVER['HTTP_REFERER'];
$httpagent = $_SERVER['HTTP_USER_AGENT'];

$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];

$headers = "MINE-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: Erin <erinkuzma@yahoo.com>\r\n";
$headers .= "From: {$visitor} <{$visitormail}>\r\n";

// This is a true regex check for a valid email
if (!preg_match("/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/", $_POST['visitormail'])) {
   echo "<h2>Use Back - Enter valid e-mail</h2>\n";
   $dontsend = true;
}

if (empty($visitormail) || empty($_POST['notes'])) {
   echo "<h2>Use Back - fill in all fields</h2>\n";
   $dontsend = true;
}

if ($dontsend) {
   echo "<h2>Feedback was NOT submitted</h2>\n";
   die();
}

$todayis = date("l, F j, Y, g:i a");

$attn = $attn;
$subject = $attn;

$notes = (get_magic_quotes_gpc()) ? stripslashes($_POST['notes']) : $_POST['notes'];

$message = " $todayis [EST] \r\n
Attention: $attn \r\n
Message: $notes \r\n
From: $visitor ($visitormail) \r\n";

$question = "How often do you visit MOSI? $_POST[Q1] \n";
$question .= "How often do you visit museums in general? $_POST[Q2] \n";
$question .= "What is your gender? $_POST[Q3] \n";
$question .= "What is your age group? $_POST[Q4] \n";
$question .= "Do you currently live in Tampa? $_POST[Q5] \n";
$question .= "Including yourself, how many persons are there in your group or family visiting the museum with you today? $POST[Q6] \n";
$question .= "How many of those are aged 12 or over, again, including yourself? $_POST[Q7]\n";


if (!empty($myemail)) {
   if (mail($myemail, $subject, $message . $question, $headers)) {
      echo 'Email sent';
   } else {
      echo 'Error sending email';
   }
}

?>

<p align="left" class="style1">
<strong>Date:</strong> <?php echo $todayis ?>
<br />
<strong>Thank You :</strong> ( <?php echo $visitormail; ?> )
<br />

<br />
<strong>Message:</strong><br />
<br><?php echo nl2br($notes); ?></br>

<br><?php echo nl2br($question) . '<br /><br />' . $ip;?></br>
<br><br>
<a href="WhatDoYouThink.php"> Send another message.. </a></p> </td>
</tr>
</table>
<p>&nbsp;</p></td>
</tr>
</table>[/code]
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43214
Share on other sites

It must be a problem with your server, because I've tested it and it works fine.

This is the email I got in my inbox:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Thursday, June 8, 2006, 3:06 pm [EST]

Attention:

Message: hello

From: (somebody@someplace.com)
How often do you visit MOSI? Less than once a year
How often do you visit museums in general? A few times a year
What is your gender? Male
What is your age group? 65 and over
Do you currently live in Tampa? Yes
Including yourself, how many persons are there in your group or family visiting the museum with you today?
How many of those are aged 12 or over, again, including yourself? 3[/quote]

Check this again:
[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95326\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=95326[/a]
Link to comment
https://forums.phpfreaks.com/topic/11458-email-survey-results/#findComment-43223
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.