How to send e-mail with php

Discussion in 'PHP' started by gurko, Jan 23, 2009.

  1. #1
    I am at the beginning of php learning and I am confused about how to send e-mail with php. I checked some tutorial but nowhere wrote about where to include outgoing server data like password, username, etc.

    Is necessary to have PEAR Mail Package if I use mail() function?

    I hope my question is not too basic.
     
    gurko, Jan 23, 2009 IP
  2. Valdor

    Valdor Well-Known Member

    Messages:
    450
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    185
    #2
    have a look at this http://phpmailer.codeworxtech.com/ it is open source code (free).
    You dont need mail details with php's mail() function you just put a few details in the headers section.

    If you use phpmailer then you can opt to use SMTP which is better and the documentation tells you all you need to know.

    Just remember that SMTP details for cpanel hosting are usually:
    server: mail.yourdomain.com
    username: cpanel login name
    password: cpanel login password.

    not your email account login details.
     
    Valdor, Jan 23, 2009 IP
  3. gurko

    gurko Greenhorn

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    that is where I am getting confused. If you don't need mail details with php's mail(), how it know through which mail server will message be sent and if account data are from you? Or is even possible to send message without mail server through http? If so, which way is better?

    Thank you!
     
    gurko, Jan 23, 2009 IP
  4. gurko

    gurko Greenhorn

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    but through what is send an e-mail when using mail() if not via SMTP?
     
    gurko, Jan 23, 2009 IP
  5. jonhel

    jonhel Peon

    Messages:
    26
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    the PHP mail function uses UNIX sendmail which is not sent via SMTP.

    I recently moved to using the PHP mailer class because I wanted to use html and attachments etc. and found this the easiest way to do so.

    Also mail() is of no use if you want to know when people have supplied incorrect addresses etc. because there's no feedback.

    Jonathan
     
    jonhel, Jan 23, 2009 IP
  6. prasunsen

    prasunsen Peon

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The mail problem of using mail() function is that the emails usually end up in the spam boxes. You'd better use some class like phpmailer.
     
    prasunsen, Jan 23, 2009 IP
  7. bbrez1

    bbrez1 Banned

    Messages:
    208
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I think the best for you would be that you just use a mail class :)
     
    bbrez1, Jan 23, 2009 IP
  8. mrmaf

    mrmaf Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    mrmaf, Jan 23, 2009 IP