SitePoint Sponsor

User Tag List

Page 2 of 4 FirstFirst 1234 LastLast
Results 26 to 50 of 78
  1. #26
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not recieving the attachment

    Hiya, great tutorial!

    I am having a problem with the sending of an attachment though, i am modifying the script slightly as most are i presume. What i am trying to do is send two e-mails out of the one form as well as sign a user up to a database from another tutorial, which doesn't seem to be the problem. It is just one is sending an attachment and the other is not. The following code gets no errors but the attachement is not recieved, but content is complete:



    <<<<-----------------------------CODE------------------------>>>>>>
    <?php
    else:
    // Process signup submission
    dbConnect('srecruit');

    if ($_POST['newfname']=='' or $_POST['newlname']==''
    or $_POST['newemail']=='' or $_POST['newtel']=='') {
    error('One or more required fields were left blank.\\n'.
    'Please fill them in and try again.');
    }

    // Check for existing user with the new email
    $sql = "SELECT COUNT(*) FROM users WHERE email = '$_POST[newemail]'";
    $reg_result = mysql_query($sql);
    if (!$reg_result) {
    error('A database error occurred in processing your '.
    'submission.\\nIf this error persists, please '.
    'contact you@example.com.');
    }
    if (@mysql_result($reg_result,0,0)>0) {
    error('A user already exists with your chosen userid.\\n'.
    'Please try another.');
    }

    $sql = "INSERT INTO users SET
    fname = '$_POST[newfname]',
    lname = '$_POST[newlname]',
    email = '$_POST[newemail]',
    tel = '$_POST[newtel]'";
    if (!mysql_query($sql))
    error('A database error occurred in processing your '.
    'submission.\\nIf this error persists, please '.
    'contact you@example.com.');

    // Email the new password to the person.
    $message = "G'Day!

    Your personal account for the Project Web Site
    has been created! To log in, proceed to the
    following address:

    http://www.example.com/

    Your personal login ID and password are as
    follows:

    E-mail: $_POST[newemail]

    You aren't stuck with this password! Your can
    change it at any time after you have logged in.

    If you have any problems, feel free to contact me at
    <you@example.com>.

    -Your Name
    Your Site Webmaster
    ";

    mail($_POST['newemail'],"Your Password for Your Website",
    $message, "From:Your Name <you@specialist-recruit.com>");

    // Read POST request params into global vars
    $to = "kesterwynyard@pure-tech.co.uk";
    $from = "signup@specialist-recruit.com";
    $subject = "New Website User";
    $messageatt = "get out!";

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

    $headers = "From: $from";

    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}\"";

    // Add a multipart boundary above the plain message
    $messageatt = "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" .
    $messageatt . "\n\n";

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

    // Add file attachment to the message
    $messageatt .= "--{$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";
    }

    // Send the message
    $ok = mail($to, $subject, $messageatt, $headers);
    if ($ok) {
    echo "<p>Mail sent! Yay PHP!</p>";
    } else {
    echo "<p>Mail could not be sent. Sorry!</p>";
    }
    ?>
    <<<<-----------------------------CODE------------------------>>>>>>



    Just prior to posting this thread, i hadn't actually uploaded the two pages untouched, so i have done so. On a submit of the untouched tutorial i get the following error:

    Warning: filesize(): Stat failed for C:\WINDOWS\TEMP\php1EA3.tmp (errno=2 - No such file or directory) in \\nas22ent\domains\s\specialist-recruit.com\user\htdocs\mail.php on line 23

    Any ideas to if these problems are linked or any solution to the orginal?

    Sorry about the length!
    Any help is much appreciated!

    Kester Wynyard

  2. #27
    SitePoint Enthusiast spsalter's Avatar
    Join Date
    Apr 2005
    Location
    A little to the left
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there a simple to handle errors? I get the "Mail could not be sent. Sorry!" error, but would like more information about what is causing the error. Maybe I just need to change the .ini settings?

    Added code...assume email addresses are valid:
    Code:
    <?
    if ($position == "Counselor") {
    	$toMail == "email1@yoursite.com";
    } else {
    	$toMail == "email2@yoursite.com";
    }
    // Read POST request params into global vars
    $to = $toMail;
    $from = $_POST['from'];
    $subject = "Resume Submittal";
    $position = $_POST['position'];
    $message = $_POST['message'];
    
    // Obtain file upload vars
    $fileatt = $_FILES['fileatt']['tmp_name'];
    $fileatt_type = $_FILES['fileatt']['type'];
    $fileatt_name = $_FILES['fileatt']['name'];
    
    $headers = "From: $from";
    
    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}\"";
    
      // 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";
    
      // Base64 encode the file data
      $data = chunk_split(base64_encode($data));
    
      // Add file attachment to the message
      $message .= "--{$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";
    }
    
    // Send the message
    $ok = @mail($to, $subject, $position, $message, $headers);
    if ($ok) {
      echo "<p>Mail sent! Yay PHP!</p>";
    } else {
      echo "<p>Mail could not be sent. Sorry!</p>";
    }
    ?>

  3. #28
    cloudy
    SitePoint Community Guest
    This tutorials are good. But i am still confusing on how to setup the SMTP server.

  4. #29
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No one

  5. #30
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This statement in your code:

    Code:
    $fd = fopen($sourcefile, "r");
    needs to be this instead:

    Code:
    $fd = fopen($sourcefile, "rb");
    Don't know if that's all you have to do though. Please compare your code with what I posted in this thread (post #11) to see if you can find other differences. Then you'll probably have your problem solved.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  6. #31
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @ vinyl J

    Tried changing the 'r' to 'rb' but it looks like something else stoping it from showing me the file

    I looked at your previous post and the script you supplied works

    I might just use this instead to save my self the headache

  7. #32
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're certainly welcome to use my script.

    You might be interested in a slightly modified version of the mail.php script that I made. It has some anti-spam measures that weren't included with the script in that other post. Here is that modified script:
    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']);
    $yourdomain = "yoursitename.com";
    $YourWebsiteURL = "http://www.".$yourdomain."/";
    $fromtest		= strpos($from, $yourdomain);
    
    // If they call this page direct from the browser, send them away because they havent filled in
    // the form! Also, test to see if some joker is using my domain as their email addy
    if($from == "" || $fromtest == true) {
     header("location: $YourWebsiteURL");
     exit();
    }
    
    // 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";	
    }
    
    //Validate the email address used
    if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$', $from)) {
    	// 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>";
    	}
    else {
    	echo "<p>Your email address is invalid. 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

  8. #33
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I took the last echo out and it works fine

    Thanks for the script! Don't know why it's playing up but does not matter.

  9. #34
    SitePoint Enthusiast aaroncampbell's Avatar
    Join Date
    Apr 2004
    Location
    Buckeye, AZ
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Motions 2082. You were'nt ending the if(eregi('...', $from)) before you did the else. You had this:
    Code:
    if(eregi('...', $from)){
      if($ok){
      } else {
      } else {
    }
    Should have been like this:
    Code:
    if(eregi('...', $from)){
      if($ok){
      } else {
      }
    } else {
    }
    Notice the red }?

  10. #35
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,524
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about the mistake. I was trying to copy/paste code from my the script I use on my website, which itself is a little bit more complicated than the one here.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  11. #36
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by motion2082
    ANYONE WANT TO ADD TO THIS HELPFUL THREAD?
    Without even reading this thread, I'll give you the best advice you're going to get here. Download Richard Heyes' htmlMimeMail5, POP3, and mimeDecode classes and quit driving yourself bananas over this stuff.

    http://www.phpguru.org

  12. #37
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Version 1.3.1? Version 5 is as easy as falling off a ladder, dude.

  13. #38
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need to understand how it works. The method names are self-explanatory. Read the article here:

    http://www.phpguru.org/static/htmlMimeMail5.html

    Download the PHP 4 version here:

    http://www.phpguru.org/downloads/htm...l-2.5.1.tar.gz

  14. #39
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The file in that screenshot got renamed with the .tar extension twice somehow. It should be .tar.gz Rename it then try opening it in WinZip.

  15. #40
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I extracted the zip file....now what do i do? I see 9 PHP files, jumping off a ladder looks easier at this stage

  16. #41
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the same code without all of the author's commentary. Just make a form and insert the $_POST variables from the form into the strings that get passed to the object's methods where appropriate.

    PHP Code:
    <?php
    require_once("htmlMimeMail5.php");

    $mail = new htmlMimeMail5();
    $mail->setFrom("Richard <richard@example.com>");
    $mail->setSubject('Test email');
    $mail->setPriority('high');
    $mail->setText('Sample text');
    $mail->setHTML('<body background="background.gif"><b>Sample HTML</b></body>');
    $mail->addEmbeddedImage(new fileEmbeddedImage('background.gif''image/gif', new Base64Encoding()));
    $mail->addAttachment(new fileAttachment('example.zip''application/zip', new Base64Encoding()));
    $mail->send(array('richard@example.com'));

    ?>

  17. #42
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just make a form and insert the $_POST variables from the form into the strings that get passed to the object's methods where appropriate.
    Easier said than done, Im not familar with this method

    Compared with the example I was using this is totally different, how does the attachment get attached?

  18. #43
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by motion2082
    Ok I extracted the zip file....now what do i do? I see 9 PHP files, jumping off a ladder looks easier at this stage
    Put the 9 files in a new folder in your document root and put require('/whatever/the/folder/is/called/htmlMimeMail.php') in your script.

  19. #44
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by motion2082
    Easier said than done, Im not familar with this method

    Compared with the example I was using this is totally different, how does the attachment get attached?
    Like this:

    PHP Code:
    ...
    $mail->setFrom($_POST['from']);
    $mail->setSubject($_POST['subject']);
    ...
    $mail->addAttachment(new fileAttachment($_FILES['fileatt']['name'],$_FILES['fileatt']['type'], new Base64Encoding()));
    ... 
    except you would probably need to use move_uploaded_file() to move the files to your document root first and put in that filename because PHP can only find it by tmp_name if it's still in the /tmp folder.

  20. #45
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, for PHP 4.3.2 you can do this:

    PHP Code:
    $attachment $mail->getFile($_FILES['fileatt']['tmp_name']);
    $mail->addAttachment($attachment,$_FILES['fileatt'['name'],$_FILES['fileatt']['type']); 
    The addAttachment and addHtmlImage methods changed in version 5.

  21. #46
    SitePoint Zealot
    Join Date
    Sep 2005
    Location
    Perth, Australia
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So PHP would be:

    PHP Code:
    <?php 
    require_once("htmlMimeMail5.php"); 

    $mail = new htmlMimeMail5(); 
    $mail->setFrom("Richard <richard@example.com>"); 
    $mail->setSubject('Test email'); 
    $mail->setPriority('high'); 
    $mail->setText('$to, $from'); 
    $mail->setHTML('$enquiry, $id, $etc'<b>Sample HTML</b></body>'); 
    $mail->addEmbeddedImage(new fileEmbeddedImage('
    background.gif', 'image/gif', new Base64Encoding())); 
    $mail->addAttachment(new fileAttachment($_FILES['
    fileatt']['name'],$_FILES['fileatt']['type'], new Base64Encoding())); 
    $mail->send(array('
    richard@example.com')); 

    ?>
    And HTML would be

    HTML Code:
    <html>
    <head>
    <title>Send an Email</title>
    </head>
    <body>
    <h1>Send an Email</h1>
    <form action="htmlmimemail.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><input type="submit" value="Send" /></p>
    </form>
    </body>
    </html>
    ?????????????????

    ..

  22. #47
    SitePoint Addict
    Join Date
    Nov 2005
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. You need to get version 2.5.1. htmlMimeMail5 is for PHP 5. You need to require() it in your own script, not make it the form action. Then catch up on my last few posts where I explained passing the $_POST variables to the mail methods.

    It's 2:30 AM here, so I'm gonna call it a night. I'll check in tomorrow and see how you're doing.

  23. #48
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Great email tut.

    Thanx

  24. #49
    SitePoint Member arcooke's Avatar
    Join Date
    Oct 2005
    Location
    Dallas, TX USA
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awesome tutorial. Just what I needed. I'm really glad you mentioned that you can use your ISP's SMTP server if running a server from home.

    Thanks

  25. #50
    noel
    SitePoint Community Guest
    Hi there, great tutorial! Was wondering if anyone has tried the multiple file upload suggestion?


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
  •