PHP Scripts Development » PHP snippets and scripts forum

[closed]

Mail error sending attachments

(11 posts)

Great offers not only for geeks!


  1. User has not uploaded an avatar

    shanmu
    Member

    I need your help

    i tried this example

    <?php
    function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
        $file = $path.$filename;
        $file_size = filesize($file);
        $handle = fopen($file, "r");
        $content = fread($handle, $file_size);
        fclose($handle);
        $content = chunk_split(base64_encode($content));
        $uid = md5(uniqid(time()));
        $name = basename($file);
        $header = "From: ".$from_name." <".$from_mail.">\r\n";
        $header .= "Reply-To: ".$replyto."\r\n";
        $header .= "MIME-Version: 1.0\r\n";
        $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
        $header .= "This is a multi-part message in MIME format.\r\n";
        $header .= "--".$uid."\r\n";
        $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
        $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
        $header .= $message."\r\n\r\n";
        $header .= "--".$uid."\r\n";
        $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use diff. tyoes here
        $header .= "Content-Transfer-Encoding: base64\r\n";
        $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
        $header .= $content."\r\n\r\n";
        $header .= "--".$uid."--";
        if (mail($mailto, $subject, "", $header)) {
            echo = "mail send ... OK"; // or use booleans here
        } else {
            echo = "mail send ... ERROR!";
        }
    }
    // how to use
    $my_file = "somefile.zip";
    $my_path = $_SERVER['DOCUMENT_ROOT']."/your_path_here/";
    $my_name = "Olaf Lederer";
    $my_mail = "my@mail.com";
    $my_replyto = "my_reply_to@mail.net";
    $my_subject = "This is a mail with attachment.";
    $my_message = "Hallo,\r\ndo you like this script? I hope it will help.\r\n\r\ngr. Olaf";
    mail_attachment($my_file, $my_path, "recipient@mail.org", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
    ?>

    iam getting error in

    if (mail($mailto, $subject, "", $header))

    My output is looking

    From: Olaf Lederer Reply-To: shanmugapriya.v@fornx.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="7a3b6be891c70468d6c07c47bd7e5e68" This is a multi-part message in MIME format. --7a3b6be891c70468d6c07c47bd7e5e68 Content-type:text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit --7a3b6be891c70468d6c07c47bd7e5e68 Content-Type: application/octet-stream; name="example.zip" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="example.zip" UEsDBBQAAgAIAG9/eSh7cy0TEQAAAH0DAAAwAAAAaHR0cGRvY3MvdGVzdC9odG1sLm1pbWUubWFp bC9kdW1teS50ZXh0LmZpbGUudHh0i4ggAfByRYwqH1U+qpxKygFQSwECFAAUAAIACABvf3koe3Mt ExEAAAB9AwAAMAAAAAAAAAABACAAtoEAAAAAaHR0cGRvY3MvdGVzdC9odG1sLm1pbWUubWFpbC9k dW1teS50ZXh0LmZpbGUudHh0UEsFBgAAAAABAAEAXgAAAF8AAAAAAA== --7a3b6be891c70468d6c07c47bd7e5e68--
    Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /var/hsphere/local/home/fornx/fornx.com/html_mime_mail_2.5/aaa.php on line 29

    Posted 4 months ago #
  2. do you used the same directory structure? is the zip file on your server?

    Posted 4 months ago #
  3. User has not uploaded an avatar

    shanmu
    Member

    yes ... sir i had used the same structure

    Posted 4 months ago #
  4. User has not uploaded an avatar

    shanmu
    Member

    could you help me sir

    Posted 4 months ago #
  5. Do tried a simple mail function from the manual?

    <?php
    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: webmaster@example.com' . "\r\n" .
       'Reply-To: webmaster@example.com' . "\r\n" .
       'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    ?>
    Posted 4 months ago #
  6. User has not uploaded an avatar

    shanmu
    Member

    yes.. that program is working

    Posted 4 months ago #
  7. ... it might be that this function is not compatible with your server (it's very limited)

    I started a more advanced mail script after writing this one, try this php class.

    Posted 4 months ago #
  8. User has not uploaded an avatar

    shanmu
    Member

    i had downloaded and used the script ..

    iam getting the following error while uploading a file..

    `
    Warning: main() [function.main]: open_basedir restriction in effect. File(/hsphere/local/home/fornx/fornx.com/classes/upload/upload_class.php) is not within the allowed path(s): (/hsphere/local/home/fornx:/usr/local/lib/php:/hsphere/shared/apache/libexec:/tmp:/var/tmp) in /var/hsphere/local/home/fornx/fornx.com/classes/attach_mailer/upload_and_mail_example.php on line 5

    Warning: main(/hsphere/local/home/fornx/fornx.com/classes/upload/upload_class.php) [function.main]: failed to open stream: Operation not permitted in /var/hsphere/local/home/fornx/fornx.com/classes/attach_mailer/upload_and_mail_example.php on line 5

    Warning: main() [function.main]: open_basedir restriction in effect. File(/hsphere/local/home/fornx/fornx.com/classes/upload/upload_class.php) is not within the allowed path(s): (/hsphere/local/home/fornx:/usr/local/lib/php:/hsphere/shared/apache/libexec:/tmp:/var/tmp) in /var/hsphere/local/home/fornx/fornx.com/classes/attach_mailer/upload_and_mail_example.php on line 5

    Warning: main(/hsphere/local/home/fornx/fornx.com/classes/upload/upload_class.php) [function.main]: failed to open stream: Operation not permitted in /var/hsphere/local/home/fornx/fornx.com/classes/attach_mailer/upload_and_mail_example.php on line 5

    Warning: main() [function.include]: Failed opening '/hsphere/local/home/fornx/fornx.com/classes/upload/upload_class.php' for inclusion (include_path='.:/usr/local/lib/php') in /var/hsphere/local/home/fornx/fornx.com/classes/attach_mailer/upload_and_mail_example.php on line 5

    Fatal error: Cannot instantiate non-existent class: file_upload in /var/hsphere/local/home/fornx/fornx.com/classes/attach_mailer/upload_and_mail_example.php on line 11`

    Posted 4 months ago #
  9. Warning: main() [function.main]: open_basedir restriction in effect.

    Your web host is limited, please come back with a mature web host ;)

    Posted 4 months ago #
  10. User has not uploaded an avatar

    shanmu
    Member

    Thanks for your reply.. sir..

    I had found some errors and corrected .
    Finally iam getting this error..
    How can i elimante this error..
    i had posted the error..

    `Warning: mkdir() [function.mkdir]: open_basedir restriction in effect. File(/hsphere/local/home/fornx/fornx.com/files/mail/) is not within the allowed path(s): (/hsphere/local/home/fornx:/usr/local/lib/php:/hsphere/shared/apache/libexec:/tmp:/var/tmp) in /var/hsphere/local/home/fornx/fornx.com/classes/upload/upload_class.php on line 151

    Warning: move_uploaded_file() [function.move-uploaded-file]: open_basedir restriction in effect. File(/hsphere/local/home/fornx/fornx.com/files/mail/1208842253.jpg) is not within the allowed path(s): (/hsphere/local/home/fornx:/usr/local/lib/php:/hsphere/shared/apache/libexec:/tmp:/var/tmp) in /var/hsphere/local/home/fornx/fornx.com/classes/upload/upload_class.php on line 131`

    Posted 4 months ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.