Jump to content

Archived

This topic is now archived and is closed to further replies.

shibbi3

using the mail() function

Recommended Posts

hey everyone,

ive been trying to create a form and use the mail() function to send out an email but I cant seem to get it to work.

[code]

      $mail_header = "From: ".$name." <".$email.">\n";
      $mail_header .= 'MIME-Version: 1.0' . "\r\n";
      $mail_header .= "Content-Type: text/plain";

      mail($mailto,$mail_subject,$text,$mail_header);
 


[/code]

$mailto, $mail_subject, $text, are all gathered from the form. All variables are all defined but when I click my send button it runs the code and nothing sends. I think its not connecting to a server. Im not really sure how to work this function.

I was looking in the PHP.INI and I was just wondering if there is anything I need to setup in there for this to work?

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

Thanks for any help

Joe

Share this post


Link to post
Share on other sites
i am currently trying it on my local server.

but i eventually want it to run on a live server.

is it 2 different setups?

thanks for the help.

Share this post


Link to post
Share on other sites
You need to configure php.ini to use a smtp server if you haven't already. I remember i had probelms with trying to do this on my local server.

EDIT: It's under the module settings section of php.ini

Share this post


Link to post
Share on other sites
do you remember how to go about setting it up on a local network??

So what is the purpose of the mail() function?? because when I run the code it still returns a true value saying it has sent it.

Share this post


Link to post
Share on other sites
would this work on an local apache setup???

how would you modify the php.ini file???

im really new to this and cant seem to get this to work and i think its the smtp setup...
im trying to relay it through gmail... so smtp.gmail.com port 465

[code]

<?php
    $to = 'joe12@gmail.com';
    $subj = 'hi';
    $body = 'hello';
    $headers = "joe12@gmail.com\n";
    $p5 = '-f joe12@gmail.com';
    if(mail($to,$subj,$body,$headers,$p5))
    {
        print "successfull";
    }
    else
    {
        print "ERROR - not sent";
    }
?>

[/code]

plz heeelp

Share this post


Link to post
Share on other sites
you can only send email on a local server if you got a email sever setup but you can also setup the php.ini to use your current email provider but i say get a free email server set it up then tell php.ini what ip or domain it's atttached to.

google it set up email server on windows.

Share this post


Link to post
Share on other sites
Alright. I've setup a mail server using this program

http://www.code-crafters.com/abilitymailserver/

I found out that port 25 is blocked. So I changed the port to 465 on my local mailserver which is not blocked by my ISP but im not sure if I can even use this port to send mail (ability mail server).

I've run the code and it is still not working, and I dont think I am connecting to my SMTP server properly. (If anyone has a better program plz suggest it)

All I am trying to do is to get the following to send an email to my gmail account from my local Apache/PHP5 setup.

[code]
<?php
    $to = 'joabchen@gmail.com';
    $subj = 'hi';
    $body = 'hello';
    $headers = "joabchen@gmail.com\n";
    $p5 = '-f joabchen@gmail.com';
    if(mail($to,$subj,$body,$headers,$p5))
    {
        print "successfull";
    }
    else
    {
        print "ERROR - not sent";
    }
?>
[/code]

Does anyone know a solution to this problem?

I think I am confused on the information flow with this problem. I dont see why I need an SMTP server setup and how the information is flowing from my ISP --> SMTP --> Gmail. If thats even how the information is being transferred.

if anyone has a solution plzzzzzzzzzzz help!!! thank you.

Share this post


Link to post
Share on other sites

×

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.