SitePoint Sponsor

User Tag List

Page 1 of 4 1234 LastLast
Results 1 to 25 of 78
  1. #1
    ********* Articles ArticleBot's Avatar
    Join Date
    Apr 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Article Discussion

    This is an article discussion thread for discussing the SitePoint article, "Advanced email in PHP"

  2. #2
    hello
    SitePoint Community Guest
    i want to know whether a user read my email in php(code)

  3. #3
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is a gr8 article but how can we attach a file existing on the server ?

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AHMED
    this is a gr8 article but how can we attach a file existing on the server ?
    Just generate the $fileatt, $fileatt_type, $fileatt_name and $data variables from a local file rather than an uploaded one.

  5. #5
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, have you consider PHPMailer ?

  6. #6
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cam
    Just generate the $fileatt, $fileatt_type, $fileatt_name and $data variables from a local file rather than an uploaded one.
    this is my question .. how can i generate these variables from a local file ?

  7. #7
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Change paths, I posted a quick answer in your other thread.

  8. #8
    SitePoint Addict AHMED's Avatar
    Join Date
    Oct 2002
    Location
    Egypt
    Posts
    399
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it gives undefined function error
    plz c the link
    http://www.sitepoint.com/forums/showthread.php?t=185056

  9. #9
    Wim
    SitePoint Community Guest
    Great article! Especially the mail headers part.

    How do you send an email if you want to use a specific mail server, but you do not have access to the PHP web server's settings (for example if you have shared hosting)?

  10. #10
    MASUM
    SitePoint Community Guest
    if i wanna send 2 or more attachment then what should i do?

  11. #11
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MASUM
    if i wanna send 2 or more attachment then what should i do?
    I know there is probably code already out there that does this, but I feel like I learn more when I do things myself. I built a modification for Kevin's program that will accept up to 3 attachments. Here is the code.

    index.html:
    Code:
    <html>
    <head>
    <title>Send an Email</title>
    </head>
    <body>
    <h1>Send an Email</h1>
    <form action="mail.php" method="POST" enctype="multipart/form-data">
    <p>To: <input type="text" name="to" value="" /><br />
    From: <input type="text" name="from" value="" /><br />
    Subject: <input type="text" name="subject" value="" /></p>
    <p>Message:<br />
    <textarea cols="70" rows="20" name="message"></textarea></p>
    <p>File Attachment 1: <input type="file" name="fileatt" /></p>
    <p>File Attachment 2: <input type="file" name="fileatt2" /></p>
    <p>File Attachment 3: <input type="file" name="fileatt3" /></p>
    <p><input type="submit" value="Send" /></p>
    </form>
    </body>
    </html>
    mail.php:
    Code:
    <html>
    <head>
    <title> Sending Email </title>
    </head>
    <body>
    <?php
    // Read POST request params into global vars
    $to      = $_POST['to'];
    $from    = $_POST['from'];
    $subject = $_POST['subject'];
    $message = stripslashes($_POST['message']);
    
    // Obtain file upload vars
    $fileatt		= $_FILES['fileatt']['tmp_name'];
    $fileatt_type	= $_FILES['fileatt']['type'];
    $fileatt_name	= $_FILES['fileatt']['name'];
    $fileatt2		= $_FILES['fileatt2']['tmp_name'];
    $fileatt_type2	= $_FILES['fileatt2']['type'];
    $fileatt_name2	= $_FILES['fileatt2']['name'];
    $fileatt3		= $_FILES['fileatt3']['tmp_name'];
    $fileatt_type3	= $_FILES['fileatt3']['type'];
    $fileatt_name3	= $_FILES['fileatt3']['name'];
    
    $headers = "From: $from";
    
    if (is_uploaded_file($fileatt) || is_uploaded_file($fileatt2) || is_uploaded_file($fileatt3)) {
      // Read the file to be attached ('rb' = read binary)
      if (is_uploaded_file($fileatt)) {
      	$file = fopen($fileatt,'rb');
      	$data = fread($file,filesize($fileatt));
      	fclose($file);
    
      	// Base64 encode the file data
      	$data = chunk_split(base64_encode($data));
      }
    
      if (is_uploaded_file($fileatt2)) {
      	$file2 = fopen($fileatt2,'rb');
      	$data2 = fread($file2,filesize($fileatt2));
      	fclose($file2);
    
      	// Base64 encode the file data
      	$data2 = chunk_split(base64_encode($data2));
      }
    
      if (is_uploaded_file($fileatt3)) {
      	$file3 = fopen($fileatt3,'rb');
      	$data3 = fread($file3,filesize($fileatt3));
      	fclose($file3);
    
      	// Base64 encode the file data
      	$data3 = chunk_split(base64_encode($data3));
      }
    
      // Generate a boundary string
      $semi_rand = md5(time());
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
      
      // Add the headers for a file attachment
      $headers .= "\nMIME-Version: 1.0\n" .
                  "Content-Type: multipart/mixed;\n" .
                  " boundary=\"{$mime_boundary}\"";
    
      // Add a multipart boundary above the plain message
      $message = "This is a multi-part message in MIME format.\n\n" .
                 "--{$mime_boundary}\n" .
                 "Content-Type: text/plain;\n charset=\"iso-8859-1\"\n" .
                 "Content-Transfer-Encoding: 7bit\n\n" .
                 $message . "\n\n" .
    			 "--{$mime_boundary}\n";
    
      // Add file attachment(s) to the message
      if ($fileatt_name > "") {
      	$message .= "Content-Type: {$fileatt_type};\n" .
             	     " name=\"{$fileatt_name}\"\n" .
                	  "Content-Transfer-Encoding: base64\n" .
               	     "Content-Disposition: attachment;\n" .
               	     " filename=\"{$fileatt_name}\"\n\n" .
                	  $data . "\n" .
                	  "--{$mime_boundary}\n";
    	}
    	
    	
      if ($fileatt_name2 > "") {
      	$message .=  "Content-Type: {$fileatt_type2};\n" .
             	     " name=\"{$fileatt_name2}\"\n" .
                	  "Content-Transfer-Encoding: base64\n" .
               	     "Content-Disposition: attachment;\n" .
               	     " filename=\"{$fileatt_name2}\"\n\n" .
                	  $data2 . "\n" .
                	  "--{$mime_boundary}\n";
    	}
    	
    	
      if ($fileatt_name3 > "") {
      	$message .=  "Content-Type: {$fileatt_type3};\n" .
             	     " name=\"{$fileatt_name3}\"\n" .
                	  "Content-Transfer-Encoding: base64\n" .
               	     "Content-Disposition: attachment;\n" .
               	     " filename=\"{$fileatt_name3}\"\n\n" .
                	  $data3 . "\n" .
                	  "--{$mime_boundary}";
    	}
    	$message .=  "--\n\n";	
    }
    
    // Send the message
    $ok = @mail($to, $subject, $message, $headers);
    if ($ok) {
      echo "<p>Mail sent! Yay PHP!</p>";
    } else {
      echo "<p>Mail could not be sent. Sorry!</p>";
    }
    ?>
    </body>
    </html>
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  12. #12
    Fred
    SitePoint Community Guest
    I am getting this error in my maillog when I use the PHP command:
    Dec 29 20:58:25 www sendmail[23641]: iBU1wPd23641: ruleset=check_mail, arg1=<postmaster@localhost>, relay=win03.xxx.com [66.xx.206.210], reject=553 5.5.4 <postmaster@localhost>... Real domain name required for sender address
    Dec 29 20:58:25 www sendmail[23641]: iBU1wPd23641: from=<postmaster@localhost>, size=309, class=0, nrcpts=0, proto=ESMTP, daemon=MTA, relay=win03.xxx.com [66.xx.206.210]

  13. #13
    Brian Moreau
    SitePoint Community Guest
    mail.php:
    Mail sent! Yay PHP!

  14. #14
    Rohan
    SitePoint Community Guest
    I cannot get this code to email an attachment! Only the file name comes over. What should I be doing. Anyone - Please help me - this is for a non for profit site and volunteer programming.

    <HTML>
    <BODY>
    <PRE>&lt;?
    /*

    */

    $mailto = 'timmytiger32@hotmail.com' ;

    $subject = "Awardee Nomination" ;

    $formurl = "http://www.cast-utech.ca/awardees/nonform.html" ;
    $errorurl = "http://www.cast-utech.ca/awardees/err.html" ;
    $thankyouurl = "http://www.cast-utech.ca/awardees/thanks.html" ;


    $name = $_POST['name'] ;
    $address = $_POST['address'] ;
    $city = $_POST['city'] ;
    $province = $_POST['province'] ;
    $postal = $_POST['postal'] ;
    $email = $_POST['email'] ;
    $telephone = $_POST['telephone'] ;
    $start = $_POST['start'] ;
    $end = $_POST['end'] ;
    $job = $_POST['job'] ;
    $utech = $_POST['utech'] ;
    $prof = $_POST['prof'] ;
    $society = $_POST['society'] ;
    $cuaa = $_POST['cuaa'] ;
    $community = $_POST['community'] ;
    $other = $_POST['other'] ;
    $comments = $_POST['comments'] ;

    $nomname = $_POST['nomname'] ;
    $nomadd = $_POST['nomadd'] ;
    $nomcity = $_POST['nomcity'] ;
    $nomprov = $_POST['nomprov'] ;
    $nomcode = $_POST['nomcode'] ;
    $nomemail = $_POST['nomemail'] ;
    $nomtele = $_POST['nomtele'] ;

    // Obtain file upload vars
    $fileatt = $_FILES['fileatt']['tmp_name'];
    $fileatt_type = $_FILES['fileatt']['type'];
    $fileatt_name = $_FILES['fileatt']['name'];

    $http_referrer = getenv( "HTTP_REFERER" );

    if (is_uploaded_file($fileatt)) {
    // Read the file to be attached ('rb' = read binary)
    $file = fopen($fileatt,'rb');
    $data = fread($file,filesize($fileatt));
    fclose($file);

    // Generate a boundary string
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

    // Add the headers for a file attachment
    $headers .= "\nMIME-Version: 1.0\n" .
    "Content-Type: multipart/mixed;\n" .
    " boundary=\"{$mime_boundary}\"";

    // Base64 encode the file data
    $data = chunk_split(base64_encode($data));

    /* Add a multipart boundary above the plain message
    $message = "This is a multi-part message in MIME format.\n\n" .
    "--{$mime_boundary}\n" .
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $message . "\n\n";

    */







    if (!isset($_POST['email'])) {
    header( "Location: $formurl" );
    exit ;
    }
    if (empty($name) || empty($email) || empty($comments)) {
    header( "Location: $errorurl" );
    exit ;
    }
    if (get_magic_quotes_gpc()) {
    $comments = stripslashes( $comments );
    }


    $messageproper =

    "------------------------- AWARDEE INFORMATION -------------------------\n" .
    "Name: -$name\n" .
    "Address: -$address\n" .
    "City: -$city\n" .
    "Province: -$province\n" .
    "Postal Code: -$postal\n" .
    "E-mail: -$email\n" .
    "Telephone: -$telephone\n" .
    "Attended Cast from: -$start\n" .
    "to: -$end\n" .
    "Profession: -$job\n" .
    "Contribution: -\n" .
    "Utech: -$utech\n" .
    "prof: -$prof\n" .
    "society: -$society\n" .
    "cuaa: -$cuaa\n" .
    "community: -$community\n" .
    "other: -$other\n" .

    "Other Information for this Nominatiom\n" .
    "$comments\n" .
    // Add file attachment to the message
    $comments .= "--{$mime_boundary}\n" .
    "Content-Type: {$fileatt_type};\n" .
    " name=\"{$fileatt_name}\"\n" .
    "Content-Disposition: attachment;\n" .
    " filename=\"{$fileatt_name}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $data . "\n\n" .
    "--{$mime_boundary}--\n";
    }


    "----------------------------------------------------------------------\n\n" .
    "This message was sent from:\n" .
    "$http_referrer\n" .
    "By;\n" .
    "$nomname\n" .
    "$nomadd\n" .
    "$nomcity\n" .
    "$nomprov\n" .
    "$nomcode\n" .
    "$nomemail\n" .
    "$nomtele\n" .



    "\n\n-----------------------------------------------------------------------\n" ;

    mail($mailto, $subject, $messageproper, "From: \"$nomname\" &lt;$nomemail&gt;\nReply-To: \"$nomname\" &lt;$nomemail&gt;\nX-Mailer: chfeedback.php 2.03" );
    header( "Location: $thankyouurl" );
    exit ;


    ?&gt;
    </PRE>
    </BODY></HTML>

  15. #15
    sara
    SitePoint Community Guest
    Can you add bcc to the mail?

  16. #16
    SitePoint Enthusiast aaroncampbell's Avatar
    Join Date
    Apr 2004
    Location
    Buckeye, AZ
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sara
    Can you add bcc to the mail?
    Yes, as a matter of fact, in the Advanced email in PHP section, he does just that:
    "cc: Interested <someone@some.net>\n" .
    "Bcc: Me Too <metoo@some.net>\n" .
    It is done with the optional "additional headers"

  17. #17
    Bjorn
    SitePoint Community Guest
    It doesn't get much easier than that. Thanks man.

    The only thing that can be improved is maybe deeper connection to php, but whattheheck.

  18. #18
    kris
    SitePoint Community Guest
    How to send e-mail to smtp server with authorization

  19. #19
    Anoop PK
    SitePoint Community Guest
    Well done. Thanks man for your article.

  20. #20
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Decent article for a beginner. Kev is always clear.

  21. #21
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I adapted the script in this article to email an attached tab-delimited file created on the fly from mysql data. It works great with one exception. When I open the file in Excel, all the space and tab characters have been replaced with the ASCII nul character.

    Does anyone know the cause of this problem?

  22. #22
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bbergin
    I adapted the script in this article to email an attached tab-delimited file created on the fly from mysql data. It works great with one exception. When I open the file in Excel, all the space and tab characters have been replaced with the ASCII nul character.

    Does anyone know the cause of this problem?
    I see this is your first post. Welcome to the SitePoint forums!

    Are you sure you encoded the data with basecode 64? That might possibly be the problem. OTOH, if it doesn't seem to have anything to do with it, post your code. Maybe someone will spot something in it.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  23. #23
    SitePoint Member
    Join Date
    Jun 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vinyl-junkie
    I see this is your first post. Welcome to the SitePoint forums!

    Are you sure you encoded the data with basecode 64? That might possibly be the problem. OTOH, if it doesn't seem to have anything to do with it, post your code. Maybe someone will spot something in it.
    Yes, I tried it both with and without base64 encoding. Neither fixed the bug. I found a workaround though. If I first open the file in notepad and then copy and paste it into Excel, the tab characters render as they should and place each data field in its own column. I'd still like to know why the tabs are replaced by nul characters if I open the file in Excel directly.

    My code is attached.
    Attached Files Attached Files

  24. #24
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bbergin - Your code attachment is still pending approval as I write this, but I thought of something else to try in the meantime. See if using htmlentities does anything for you.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  25. #25
    php4tric
    SitePoint Community Guest
    great tut, i receive file as attachment, but no message!?? what could i possible be doing wrong?


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
  •