Jump to content

mail function help


corbeeresearch

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

 

Link to comment
Share on other sites

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

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.