Emailing via Script

Discussion in 'PHP' started by adamjblakey, Aug 29, 2008.

  1. #1
    Hi,

    I have a script on my website and when a user posts to the script it sends an email out.

    Untill recently this has been working fine then all of a sudden it stopped sending email's out.

    In the script i have this section:

    
    $headers = "From: Website Name <noreply@website.com>\n";
    $headers .= "Reply-To: Website Name <noreply@website.com>\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
    
    PHP:
    I found if i replace the above with this:

    
    $headers = "From: Website Name <>\n";
    $headers .= "Reply-To: Website Name <>\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
    
    PHP:
    It works fine, but the emails come through without saying what email address it has come from.

    Why would this happen and how can i fix it so i can put the email address back in.

    Cheers,
    Adam
     
    adamjblakey, Aug 29, 2008 IP
  2. Tjcrazy

    Tjcrazy Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Im not the best with troubleshooting, but if you haven't edited it, its probably a php update on your server.
     
    Tjcrazy, Aug 29, 2008 IP
  3. Supah Fly

    Supah Fly Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I made a function for emailing >.>

    function emailgo($email, $from, $subject, $content) {
    $ip = $_SERVER['REMOTE_ADDR'];
    $frmheader = "From: ".$from." (".$email.") ".$ip;
    $contactemail = 'youremailplz';
    // $email is the person's email, $from is their name, $subject can be predefined but whatever. $content is their message.
    
    if ($content != "" && $from != "" && $ip != "" && $email != "") {
       if (isset($_COOKIE['emailz'])) {
       echo("You can send another message in an hour.");
       }
       else {
       mail($contactemail, $subject, $content, $frmheader);
       echo('Your message has successfully been sent to the webmaster.
       <br />
       We will be getting back to you soon.
       <br /><br />
       Subject: '.$subject.'<br />
       Content: '.$content.'<br />
       Header: '.$frmheader);
       setcookie("emailz", $ip, time()+3600);
       }
    }
      else {
       echo("Please fill out all parts of the form!");
    }
    }
    Code (markup):
    To use the function...

    $email = strip_tags(trim($_POST['email']));
    $from = strip_tags(trim($_POST['from']));
    $content = strip_tags(trim($_POST['content']));
    $subject = 'Site issues/Comments';
    emailgo($email, $from, $subject, $content);
    Code (markup):
    change email, from, content, and subject to whatever you like.
    also if you want just remove the cookie setting, i just made it so it wouldnt get abused.

    hope this helped you.
     
    Supah Fly, Aug 29, 2008 IP