/    Sign up×
Community /Pin to ProfileBookmark

PHP Script for email form submission + Attachment

Hi all,

I have a slight problem…..and it goes something like this…..

Tried mailto: and got into allsorts of problems….
1. It would send a blank mail with no data
2. It would send me a link to the users desktop instad of the actual .doc
3. It would not go to the thank you page after submission.

The answer became clear: Never use Mailto:.

So here I am, all Googled out, trying to place various PHP scripts into notepad only to generate a completely blank page. No fields, no buttons, no nothing at all, except yards and yards of script in the notepad. ?

What on earth am I doing wrong?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@phpshift2Dec 22.2006 — You might what to try this code. I found it on PHP.net.

[code=php]
<?php # Is the OS Windows or Mac or Linux
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
$eol="rn";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
$eol="r";
} else {
$eol="n";
} ?>

<?php
# File for Attachment
$f_name="../../letters/".$letter; // use relative path OR ELSE big headaches. $letter is my file for attaching.
$handle=fopen($f_name, 'rb');
$f_contents=fread($handle, filesize($f_name));
$f_contents=chunk_split(base64_encode($f_contents)); //Encode The Data For Transition using base64_encode();
$f_type=filetype($f_name);
fclose($handle);
# To Email Address
$emailaddress="[email protected]";
# Message Subject
$emailsubject="Heres An Email with a PDF".date("Y/m/d H:i:s");
# Message Body
ob_start();
require("emailbody.php"); // i made a simple & pretty page for showing in the email
$body=ob_get_contents(); ob_end_clean();

# Common Headers
$headers .= 'From: Jonny <[email protected]>'.$eol;
$headers .= 'Reply-To: Jonny <[email protected]>'.$eol;
$headers .= 'Return-Path: Jonny <[email protected]>'.$eol; // these two to set reply address
$headers .= "Message-ID: <".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary="".$mime_boundary.""".$eol;
$msg = "";

# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name="".$letter.""".$eol; // sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename="".$letter.""".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
# Setup for text OR html
$msg .= "Content-Type: multipart/alternative".$eol;

# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "If you are reading this, please update your email-reading-software.".$eol;
$msg .= "+ + Text Only Email from Genius Jon + +".$eol.$eol;

# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;

# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.

# SEND THE EMAIL
ini_set(sendmail_from,'[email protected]'); // the INI lines are to force the From Address to be used !
mail($emailaddress, $emailsubject, $msg, $headers);
ini_restore(sendmail_from);
?>
[/code]
Copy linkTweet thisAlerts:
@NightShift58Dec 22.2006 — Take a look at [URL]http://phpmailer.sourceforge.net/[/URL]. It'll address most mailing needs, from simple to complex.
Copy linkTweet thisAlerts:
@Pzz--DaniellaauthorDec 23.2006 — Thank you for all your help guys and sorry for the delay in replying. It appears Norton doesn't like the script in here, so couldn't get in without the whole site crashing for me until I disabled it, so I'm outta this thread now before it kicks back in. :o

Will be attempting to play with the code PHPshift2 posted and have a look at the website NightShift58 posted a link to.

Oh, such an apt signature on my profile...... ?
×

Success!

Help @Pzz--Daniella spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...