Jump to content

Archived

This topic is now archived and is closed to further replies.

phpPrincess

Email survey results

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]

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
i had the "message box" at the bottom and the questions but before i would only get whats in the message box not the questions when i sent the email.


:::banging head on desk::::

Share this post


Link to post
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

Share this post


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



Share this post


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

Share this post


Link to post
Share on other sites
I edited my post.. i accidently hit submit in the middle of pasting ;)

Also note I added single quotes inside your $_POST[] around the form names.

Share this post


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

Share this post


Link to post
Share on other sites
when i group my message and question what do i take out

ok now im getting no error but still no email and i changed the address to another one and still NADA!

Share this post


Link to post
Share on other sites


SHARK hey i combined my message and question (as u instructed) and when i hit submit and redirected page that should show the answers is blank ::banging head on desk::

Share this post


Link to post
Share on other sites
Can you post what you have so far with the changes you made?

I'll take a peek again :)

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
DAMN IT! so what should i do?

ok i have 2 other sites that support PHP and they didnt work on both!!??? why is it working for u and not me!

Share this post


Link to post
Share on other sites
Are you able to get in touch with your webhost and see if they changed anything with their PHP setup? Or even their Mail setup?

Share this post


Link to post
Share on other sites
[!--coloro:#FF6666--][span style=\"color:#FF6666\"][!--/coloro--]ok guys well i guess ill let you know what happens. THANKS FOR EVERYTHING!!! XOXO[!--colorc--][/span][!--/colorc--][size=5]

Share this post


Link to post
Share on other sites

×

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.