corbeeresearch Posted September 7, 2010 Share Posted September 7, 2010 Hi, I'm trying to do an email from a website and it won't work. It's my first time using mail function, so I'm not sure why it is not working. Please check my code <?php $name = strip_tags($_POST['name']); $email = $_POST['email']; $qst_id=strip_tags($_POST['qst_id']); //if no ajax $opt =$_POST['opt']; $s_id = $_SERVER['REMOTE_ADDR']; //email $to = 'test@test.com, test1@test.com'; $subject = 'Someone just voted'; $message = "Someone from the ip address ".$s_id; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; $headers .= 'From: Vote Detector <website@test.com>'. "\r\n"; if ($name!='') { $message = $message." with the name ".$name; } if ($email!='') { $message = $message." with email ".$email; } $message = $message." voted "."yes<br/>"; $message = $message."total number of people who declared their faith: ".$total_count." people<br/>"; $message = $message."with a total of ".$total_opt[0]." people saying yes"; $message = $message." and a total of ".$total_opt[1]." people saying no<br/>"; mail($to, $subject, $message, $headers); ?> Thanks in advancr Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 Hi there, All of the $message vars after the first call need to be done as such:- $message = "foo"; $message .= "more foo"; $message .= "even more foo"; doing this you are adding/ building the $message variable up, doing it your way you are overwriting the first instance with everything that follows, so that if you echoed $message; you would only get the contents of the last thing that you assigned to it. Hope that makes sense to you.. Cheers, Rw Quote Link to comment Share on other sites More sharing options...
corbeeresearch Posted September 7, 2010 Author Share Posted September 7, 2010 Unfortunately, I'm not receiving any messages at all. It's not reaching my email. Are there additional setups needed for it to send mail to me? Quote Link to comment Share on other sites More sharing options...
corbeeresearch Posted September 7, 2010 Author Share Posted September 7, 2010 I just asked my friend, the thing is that I emailed to myself and my friend, and it appears that he has been receiving and I'm not recieving any. I don't know why. Mine is gmail, while he actaully own the site so he has the same email as the site. Is there something wrong with my syntax or does it just works like that? Thanks again Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 Try just sending a simple string as the message first, and check that the account that is the recipient isn't marking them as spam, I have had that before now. You seem to have all the correct param's there though, so it's suggesting to me that the way you are constructing the $message var; just try something simple and build from there. Cheers, Rw PS: Definately sound's like a spam filter flaw, run a check on your email account for the message using the from email that you have defined. Though GMail does play up from time to time; I have emails not being sent & multiples being sent for some weird reason. You have changed your $message vars haven't you? - that wont affect the sending, you would just receive a blank email, Oh, and sometimes they take about 15 mins sometimes to get there; no idea why though Quote Link to comment Share on other sites More sharing options...
corbeeresearch Posted September 8, 2010 Author Share Posted September 8, 2010 Sorry for the late reply, but yes, I did follow your advice, but still I'm not receiving any from my part. could it be the site setting or should I use an smtp, though I'm not sure how to do an smtp. Thanks again Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 8, 2010 Share Posted September 8, 2010 Not sure on this, but your mixing your quoting on here, look at the headers, and change to this instead:- $headers .= "Content-type:text/html;charset=iso-8859-1 \r\n"; $headers .= "From: Vote Detector <website@test.com> \r\n"; That's the only other thing that I can see that isn't right. Have you tried a stripped down version of this code to see if it would work, nothing fancy just literally placing strings inside and sending it: if(mail("you@yourdoman", "Test Email", "This is just a test email to see if it's going","From: Vote Detector <website@test.com>")){ echo "mail successfully sent"; } else{ echo "There was a problem in sending the email"; } You can't get much more stripped down than that! Cheers, Rw Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.