Results 1 to 8 of 8

Thread: Silly email question

  1. #1

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Silly email question

    I am using WAMP, how can I test sending emails with PHP? Is it possible or do I need to be on a legit webhost like godaddy?

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Silly email question

    No you don't need to be on a webhost.

    In your php.ini configuration file, there are settings for the outgoing mail server (SMTP). Open up your php.ini and look for these settings:

    Code:
    [mail function]
    SMTP = smtp.somewhere.com
    sendmail_from = [email protected]
    You should be able to test mail in PHP using your Internet Service Providers SMTP server, and your email account with them.

    I don't know if you know how to actually send the mail in a script but the easiest way is the mail() function.
    Chris

  3. #3
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Silly email question

    Guess fixed, but when I started with php (using wamp also) there was a bug (or I was mistaken) with mail() on a windows server.

    So I got used to using phpmailer, and still use it. Very usefull and easy to use.

    Off course you first have to do what theguy said. Unless you allready set that up right when installing wamp server (guess u do use it)
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  4. #4

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Re: Silly email question

    Can I use my gmail account?

  5. #5
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Silly email question

    1 Download PHPMailer from http://phpmailer.sourceforge.net
    2 Extract to folder phpmailer
    3 Create a file email.php
    4 Paste this code and change the values as you need

    Code:
    IsSMTP(); // send via SMTP
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->Username = "[email protected]"; // SMTP username
    $mail->Password = "password"; // SMTP password
    $webmaster_email = "[email protected]"; //Reply to this email ID
    $email="[email protected]"; // Recipients email ID
    $name="name"; // Recipient's name
    $mail->From = $webmaster_email;
    $mail->FromName = "Webmaster";
    $mail->AddAddress($email,$name);
    $mail->AddReplyTo($webmaster_email,"Webmaster");
    $mail->WordWrap = 50; // set word wrap
    $mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment
    $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // attachment
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = "This is the subject";
    $mail->Body = "Hi,
    This is the HTML BODY "; //HTML Body
    $mail->AltBody = "This is the body when user views in plain text format"; //Text Body
    if(!$mail->Send())
    {
      echo "Mailer Error: " . $mail->ErrorInfo;
    }
    else
    {
      echo "Message has been sent";
    }
    ?>
    5 Open the file class.smtp.php in phpmailer directory
    6 Paste this code
    Code:
    $host = "ssl://smtp.gmail.com";
    $port = 465;
    before the line 104 #connect to the smtp server
    Hint: Search for #connect
    7 Open this page in browser and it will send the email using GMail.

    Hint: When you want to email the details from a form, set the variables using the form variables.
    eg.
    Code:
    $mail->Username=$_POST['email']
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  6. #6

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    Re: Silly email question

    I dont know what to do with the files in phpmailer.

  7. #7
    Frenzied Member StrangerInBeijing's Avatar
    Join Date
    Mar 2005
    Location
    Not in Beijing
    Posts
    1,666

    Re: Silly email question

    Just put it in a folder in your site.
    then in whichever php file you need to send a mail you just say:
    Code:
    require_once('../phpmailer/class.phpmailer.php');
    Really, just spend an hour or 2 looking at examples and stuff at codeworxtech
    Really useful once you got it sorted out, and not that hard as it look.
    Install and Configure Eclipse For both Java and PHP development
    Accessible Ajax/jQuery Forms Degrade gracefully with JavaScript Disabled

  8. #8
    New Member
    Join Date
    Dec 2008
    Posts
    1

    Re: Silly email question

    i have tried using this script but it falls down at the isSMTP(); line. i think thats the very first line of the script. how do i counteract this? this is the 3rd script i am using. none of which seem to work on my IIS server. i need to input a username and password of the server in order for the server to send the emails thru.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width