Jump to content

Smtp Email


Cathryn

Recommended Posts

:rtfm:

Hello,

I am a beginner and i am trying to send an email that shows what weather the person experienced from information they fill out on a form.

This is the form:

 

<html>
   <body>
      <form method="post" action="email.php">
         <p><h2>How is your weather now?</h2></p>
            <p>Please enter your information: </p>
            <p>
               City:<input  type="text" name="city">
               Month:<input  type="text" name="month">
               Year:<input  type="text" name="year">
            </p>
            <p>Please choose the kinds of weather you experienced from the list below.<br>
            Choose all that apply.</p>
            <p>
         <input type="checkbox" value="Sunshine" name="type[]">Sunshine<br>
         <input type="checkbox" value="Clouds" name="type[]">Clouds<br>
         <input type="checkbox" value="Rain" name="type[]">Rain<br>
         <input type="checkbox" value="Hail" name="type[]">Hail<br>
         <input type="checkbox" value="Sleet" name="type[]">Sleet<br>
         <input type="checkbox" value="Snow" name="type[]">Snow<br>
         <input type="checkbox" value="Wind" name="type[]">Wind<br>
         <input type="checkbox" value="Cold" name="type[]">Cold<br>
         <input type="checkbox" value="Heat" name="type[]">Heat<br>
         <input type="checkbox" value="Fog" name="type[]">Fog<br>
         <input type="checkbox" value="Humidity" name="type[]">Humidity
      </p>
      Anything Else? Please list in the additional weather conditions in box, separated by commas.<br>
      <input type="text", name="add" size="50"><br>
         
         <input type=submit name="submit" value="Go">
      </form>
   </body>
</html>

 

 

 

 

and here is the email coding:

 

<?php
if(isset($_POST['email'])) {
     
    $email_to = "youremail@gmail.com";
    $email_subject = "<h1>How is your weather now</h1>";
    
    $city = $_POST['city']; 
    $month = $_POST['month']; 
    $year = $_POST['year']; 
    $type = $_POST['type']; 
    $add = $_POST['add']; 
    
    $email_message .= "In ".clean_string($city) . " in the month of "  .clean_string($month).clean_string($year)." you observed the following weather: ""\n";
<?php

$check =0;
$top = array('Sunshine', 'Clouds', 'Rain', 'Hail', 'Sleet', 'Snow', 'Wind', 'Cold', 'Heat', 'Fog', 'Humidity');
                  
foreach ($_POST['type'] as $type){
   echo "<li>$type</li> \r\n";
}

?>
     
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>

 

 

I keep getting errors on the part where i put the message body of the email.

Any help would be greatly appreciated! :rtfm:

Link to comment
Share on other sites

Please use [[/tt]code] or [[tt]php] tags to post code in the future.

 

Is that exactly how the code appears in your file? Your PHP tags are all messed up. You shouldn't have a "<?php" when you're already inside of a PHP tag. Similarly, you houldn't be using "?>" if you're not intending to get out of PHP.

 

If that's not your problem, what exactly are the errors you're getting?

Link to comment
Share on other sites

It looks like you're trying to append to the string using the .= operator without the string being defined beforehand. If so, you should change that to just $email_message = ...

Link to comment
Share on other sites

Even after removing the clean_string() and using the $email_message code is not working.

 

$email_message = "In ".$city . " in the month of " . $month.$year." you observed the following weather: ""\n";

$check =0;
$top = array('Sunshine', 'Clouds', 'Rain', 'Hail', 'Sleet', 'Snow', 'Wind', 'Cold', 'Heat', 'Fog', 'Humidity');

foreach ($_POST['type'] as $type){
echo "<li>$type</li> \r\n";
}

 

Link to comment
Share on other sites

You have an extra two "" now.

 

$email_message = "In ".$city . " in the month of " . $month.$year." you observed the following weather: \n";

 

If that fails, you're still not telling us the error. And you're still not using [[tt][/tt]code] tags.

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