views:

42

answers:

2

I have a script which sends an email to myself from a contact page:

if($_POST["submit"] == "Send Message")
{
    $to = "[email protected]";
    $subject = "Message received from Contact Us";
    $message = "Email: ".$_POST["email"]."<br>";
    $message .= "Name: ".$_POST["name"]."<br>";
    $message .= "Message: ".$_POST["message"]."<br>";
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    echo mail($to,$subject,$message,$headers);
    $messageSent = TRUE;
}

It does actually echo 1. But I am not receiving any emails in my email account (gmail). I am using Codeigniter I saw there's an email library, but this should work shouldn't it?

I have a couple of other similar forms, I don't really want to integrate this library if I already have normal PHP to do it.

I know that my server is capable of sending emails because I've done it before, i have a feeling this is codeigniter related. If there is no other options, I suppose I can use the library and change the code. Any advice on this will help! Thank you :)

A: 

Codeigniter can't be responsible for your problems because mail() is a php function which can't be overwritten except by some fancy string preprocessing before including a php source file.

ITroubs
Ok, do you know why this isn't working?
Pete Herbert Penito
try var_dump(mail($to,$subject,$message,$headers)); if it says true then mail delivered your email to the outgoing server and the problem lays either in your header or at googlemail
ITroubs
BTW do you downvote every answer that doesn't give you the propper and full solution directly?
ITroubs
:) Well I ask a question and I would like an answer
Pete Herbert Penito
I agree with Pete here. Your answer is just a comment, and so it should be a reply to the question.
treeface
+1  A: 

its not CI related as you aren't making use of any CI functionality.

any reason you ~aren't~ using the email helper?

in CI:

$this->load->library('form_validation');

$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('message', 'Message', 'required');

if($this->form_validation->run() == FALSE)
{
    $this->load->view('contact-form');
}
else
{
    $this->load->library('email');

    $name = $this->input->post('name');
    $email = $this->input->post('email');
   $message= $this->input->post('message');

    $this->email->from($email, $name);
    $this->email->to('[email protected]');

    $this->email->subject('Subject');
    $this->email->message($message);
    if($this->email->send())
    {
        echo $this->email->print_debugger();
        //redirect('contact-us/thanks', 'location');
    }
   else
   {
    echo 'Something went wrong...';
   }

}

also note that mail returns true/false depending on if php was able to SEND It. there's no way of telling if the message was ever received.

try it in CI - see if there is any difference in outcome

Ross
Thanks for your time, I will try this
Pete Herbert Penito
you'll need the form_validation helper also, i omitted that from my original code. see the edited version
Ross