Results 1 to 9 of 9
  1. #1
    Deviant
    Guest

    Free Wordpress Theme - Wgrey - Free Download

    Free Wordpress Theme - Wgrey

    2 column Wgrey theme for your blogs

    Features:

    • Tested on Latest Wordpress version
    • 2 columns
    • Widget ready
    • Fixed Width
    • Cross browser compatible with IE, FF, Opera, Flock & Safari




    Demo | Download | Theme URI


    License: Free to use must keep footer intact AS IS

  2. #2
    aloycasmir
    Guest

    Send Emails Using Php (SMTP Direct)

    This is an alternative way to generate & send an email under php, rather than using the pre-defined mail() function.

    Reasons why this is useful:

    In what situations would you not want to use something as simple as the mail function?

    1.) Your php/web server does not offer mail.
    On our internal network, the mail server exists on a server other than the web server.
    Therefore, mail() will fail to send email , because
    a.) port 25 is blocked , or
    b.) sendmail is disabled

    2.) Your mail server doesn't use the default port 25 for sending email.
    If you are running a server on non-commercial service, you know what I'm talking about =-)
    This can, however, be changed via the php.ini configuration file.

    3.) Because you can.
    It allways feels good (maybe even better) when you know the how's & why's to your equipment & software. So why just send an
    e-mail when you can build one?!

    4.) Your sendmail_from value needs to change on the fly.
    Maybe you host multiple accounts, & one sendmail_from value is not enough. Maybe you are hosting something much more
    advanced & this single setting just isn't enough.
    Auto-responders, Auto-forwards, the list is endless.

    The setup:
    Since I use qmail as my MTA (mail transfer agent) that's the example you'll get. Please refer to the documentation that came with
    your MTA, should you be setting up something different.

    1st, we need to define the function to use instead of mail().
    Code:
    <?php
    
    function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {
    As you can see, we've allready got a few more arguments than mail() has to offer.

    authgMail <- my chosen function name, you can alter this as you please. Just make sure that it isn't a keyword or existing function.

    Now to setup those values...
    Code:
    $smtpServer = "192.168.xxx.xxx";   //ip address of the mail server.  This can also be the local domain name
    $port = "25";                     // should be 25 by default, but needs to be whichever port the mail server will be using for smtp
    $timeout = "45";                 // typical timeout. try 45 for slow servers
    $username = "sales@mydomain.com"; // the login for your smtp
    $password = "myPA$$";            // the password for your smtp
    $localhost = "127.0.0.1";       // Defined for the web server.  Since this is where we are gathering the details for the email
    $newLine = "\r\n";             // aka, carrage return line feed. var just for newlines in MS
    $secure = 0;                  // change to 1 if your server is running under SSL
    Those should be the only values that you need to change to match your own internal settings.
    The rest is the functionality of the server & those values. The variable $smtpResponse is going to let you know what's going on.
    You can use it to show you every step along the way, or just show errors reported back from the mail server.
    Now, lets build that e-mail!

    Code:
    //connect to the host and port
    $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
    $smtpResponse = fgets($smtpConnect, 4096);
    if(empty($smtpConnect)) {
       $output = "Failed to connect: $smtpResponse";
       echo $output;
       return $output;
    }
    else {
       $logArray['connection'] = "<p>Connected to: $smtpResponse";
       echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
    }
    
    //you have to say HELO again after TLS is started
       fputs($smtpConnect, "HELO $localhost". $newLine);
       $smtpResponse = fgets($smtpConnect, 4096);
       $logArray['heloresponse2'] = "$smtpResponse";
    //request for auth login
    fputs($smtpConnect,"AUTH LOGIN" . $newLine);
    $smtpResponse = fgets($smtpConnect, 4096);
    $logArray['authrequest'] = "$smtpResponse";
    
    //send the username
    fputs($smtpConnect, base64_encode($username) . $newLine);
    $smtpResponse = fgets($smtpConnect, 4096);
    $logArray['authusername'] = "$smtpResponse";
    
    //send the password
    fputs($smtpConnect, base64_encode($password) . $newLine);
    $smtpResponse = fgets($smtpConnect, 4096);
    $logArray['authpassword'] = "$smtpResponse";
    
    //email from
    fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
    $smtpResponse = fgets($smtpConnect, 4096);
    $logArray['mailfromresponse'] = "$smtpResponse";
    
    //email to
    fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
    $smtpResponse = fgets($smtpConnect, 4096);
    $logArray['mailtoresponse'] = "$smtpResponse";
    
    //the email
    fputs($smtpConnect, "DATA" . $newLine);
    $smtpResponse = fgets($smtpConnect, 4096);
    $logArray['data1response'] = "$smtpResponse";
    
    //construct headers
    $headers = "MIME-Version: 1.0" . $newLine;
    $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
    $headers .= "To: $nameto <$to>" . $newLine;
    $headers .= "From: $namefrom <$from>" . $newLine;
    
    //observe the . after the newline, it signals the end of message
    fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
    $smtpResponse = fgets($smtpConnect, 4096);
    $logArray['data2response'] = "$smtpResponse";
    
    // say goodbye
    fputs($smtpConnect,"QUIT" . $newLine);
    $smtpResponse = fgets($smtpConnect, 4096);
    $logArray['quitresponse'] = "$smtpResponse";
    $logArray['quitcode'] = substr($smtpResponse,0,3);
    fclose($smtpConnect);
    //a return value of 221 in $retVal["quitcode"] is a success
    return($logArray);
    }
    Ok, that wasn't so bad... Now we can use php to error check the values passed in from a form, to verify that the server is not going
    to get some bogus value, or empty records & freak out.

    Code:
    $err=0;  // so far, so good
    $err_msg="";
    
    if($_POST['name_']!="") { echo $_POST['name_']."<br>"; }
    else {
      $err=1;
      $err_msg="You must include your name";
    }
    
    if($_POST['day_phone_']!="") {echo $_POST['day_phone_']."<br>"; }
    else {
      $err=1;
      $err_msg="You must include a daytime phone number.";
    }
    if($_POST['add_']!="") { echo $_POST['add_']."<br>"; }
    else {
      $err=1;
      $err_msg="You must include your address.";
    }
    if($_POST['city_']!="") { echo $_POST['city_']."<br>"; }
    else {
      $err=1;
      $err_msg="You must include the city.";
    }
    // Check for the existence of an AT symbol inside the email.
    if (strpos($_POST['email'],"@")) { echo $_POST['email']."<br>"; }
    else {
      $err=1;
      $err_msg="You must include a current email address.";
    }
    if($_POST['email']!="") { echo $_POST['email']."<br>"; }
    else {
      $err=1;
      $err_msg="You must include your e-mail address.";
    }
    
    echo $err_msg;
    
    if($err<=0) {
      $from="sales@mydomain.com";
      $namefrom="Internal Sales Dept. of mydomain.com";
      $to = "internal_user@mydomain.com";
      $nameto = "internal_user";
      $subject = "Email from My Domain";
      $message = "Email from My Domain";
      // this is it, lets send that email!
      authgMail($from, $namefrom, $to, $nameto, $subject, $message);
    }
    else {
      echo "<p /> This form was not filled out correctly, please correct any mistakes.";
    }
    
    ?>
    In Conclusion:
    As you can see, it very easy to send an email using php & connecting directly to your smtp server.
    In addition you can add more receivers by either adding their addresses, comma separated, to the $to variable, or by adding cc: or bcc: headers.
    If you don't receive an email using this script, then you may have installed PHP incorrectly, you may not have permission to send emails, or you may have misconfigured your MTA.
    Before running this script, verify that your current MTA is working. That way you can trouble shoot this script, knowing that your MTA is set to recieve incomming connections.



    source: dreamincode

  3. #3
    denon6
    Guest

    RE: Send Emails Using Php (SMTP Direct)

    but i think its illegal in KH3 to send mails or mass mails ... i dont know !!

  4. #4
    aloycasmir
    Guest

    RE: Send Emails Using Php (SMTP Direct)

    This is a tutorial , and this is not to be used on free hosts , if you wanna try this code , use xampp or some other such offline php implimentation .
    If you wish to use this , buy a hosting package from somewhere .

    Btw denon6 , if you're using this at a reasonable rate , not misusing it , there's no problems with using it :yes:

  5. #5
    Senior Member Array
    Join Date
    May 2011
    Posts
    157
    Thanks
    0
    Thanked 0 Times in 0 Posts

    RE: Send Emails Using Php (SMTP Direct)

    Quote Originally Posted by denon6
    but i think its illegal in KH3 to send mails or mass mails ... i dont know !!
    You're allowed to use send mail, but not start your webmail service like hotmail

  6. #6
    programmer
    Guest

    RE: Send Emails Using Php (SMTP Direct)

    thanks for this!!!

    sendmail is a available service on many of hosts like KH3

  7. #7
    sravya22
    Guest

    RE: Send Emails Using Php (SMTP Direct)

    good post thanks for that.

  8. #8
    barker.sc
    Guest

    RE: Send Emails Using Php (SMTP Direct)

    The important thing, remember, when taking input in PHP is the field names for the information you are gathering. "From" will be converted into a variable with the same name by php (it would become $from), the "subject" will be made into $subject and the "contents" of the message will be made into $contents. For submitting the actual form, we will activate the php script by using the form action tag and linking to send_mail.php3:

    <form action="send_email.php3" method="POST">

    The $to variable will be defined in the send_mail.php3 script to point to my email address (you'll see the php code momentarily), of course. I also prefill the subject with the words "diary entry suggestion" which visitors can change to something else, if they want:

    <input type="text" size="22" name="subject" value="diary entry suggestion">

    Ok, let's take a look at the code to mail the contents of the above form to me and if the process is successful it will redirect you right back to this page. In order for this code to work you will need to know the path to sendmail on your server.

    <?
    $to = "webmaster@php-scripts.com";
    $from_header = "From: $from";
    if($contents != "")
    {
    //send mail - $subject & $contents come from surfer input
    mail($to, $subject, $contents, $from_header);
    // redirect back to url visitor came from
    header("Location: $HTTP_REFERER");
    }
    else
    {
    print("<HTML><BODY>Error, no comments were submitted!");
    print("</BODY></HTML>");
    }
    ?>

    Notes: I make sure there are some comments submitted or else show an error message by using the != (not equal) with an if statement. When you want to redirect the browser using the header function (like when using the setcookie function) you must do it before any HTML. With the header and $HTTP_REFERER in the code above I am simply sending people who submit the form back where they came from, which should will be this page that calls the form. I could have easily changed the header line to read:

    header("Location: http://www.php-scripts.com/thankyou.html");

    And at a page named thankyou.html I could have thanked them for submitting the form. I could have also added HTML directly to the send_email.php3 script.

  9. #9
    aloycasmir
    Guest

    RE: Send Emails Using Php (SMTP Direct)

    Barker , you seem to be posting the same text in different topics :?
    Well , not a good thing to do - spamming


 

Bookmarks

Posting Permissions

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