/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] PHP script help for a complete beginner

Hello, I would appreciate some help.

I have a script that is used to send an email from a contact form on my website. I would like to change it so as to hardcode the subject of the email. I have tried changing a few things in the php script but nothing seems to work.

Could someone be so kind as to indicate what and where I should change so as to put a fixed text as the subject of the email. Code follows.

Thank you in advance for you help and advice

[code=php]<?php
@require_once(“../common/mails.php”);
@require_once(“../common/ipenv.php”);
$F2M_RECEIPT = false;
$TO = “”;
$URL = “”;
$SUBJECT = “”;
$LANG = “en”;
$SITELANG = “en”;
$message = “”;
$intro = “”;
$upload_dir = “data/”;
$AUTHORIZED_EXT = “”;
$UPLOADMODE = 1;
$MAXFILESIZE = 0;
while( list($key, $val) = each($_POST) ) {
if( $key == “f2memail” ) {
$TO = _local_replace_bad( $val );
} else if( $key == “f2msubj” ) {
$SUBJECT = _local_replace_bad( $val );
} else if( $key == “f2murl” ) {
$URL = _local_replace_bad( $val );
} else if( $key == “f2mlang” ) {
$LANG = strtolower( _local_replace_bad( $val ) );
} else if( $key == “f2msitelang” ) {
$SITELANG = strtolower( _local_replace_bad( $val ) );
} else if( $key == “f2muploadmode” ) {
$UPLOADMODE = strtolower( _local_replace_bad( $val ) );
} else if( $key == “f2mauthext” ) {
$AUTHORIZED_EXT = strtolower( _local_replace_bad( $val ) );
} else if( $key == “MAX_FILE_SIZE” ) {
$MAXFILESIZE = _local_replace_bad( $val );
$MAXFILESIZE /= 1024;
} else if( substr($key,0,5) != “f2mcf” ) {
$message .= “$key = ” . _local_replace_bad( $val ) . “n”;
}
}
$HREF = getenv(“HTTP_REFERER”);
$HREF = substr( $HREF, 0, strrpos( $HREF, ‘/’ ) + 1 );
if( $LANG == “en” ) {
$intro .= “This email comes from the website $HREF”;
if( $SITELANG != “” && $LANG != $SITELANG )
$intro .= ” (language=$SITELANG)”;
} else {
$intro .= “This email comes from the website $HREF”;
if( $SITELANG != “” && $LANG != $SITELANG )
$intro .= ” (langue=$SITELANG)”;
}
$ipsender = PMA_getIp();
if( $ipsender != “” ) {
if( $LANG == “en” ) {
$intro .= ” and was sent by the IP address : $ipsender”;
} else
$intro .= ” and was sent by the IP address IP : $ipsender”;
}
$error_code = “”;
if( $TO != “” && $SUBJECT != “” ) {
$headers = “Content-type: text/plain; charset=utf-8nFrom: $TOnReturn-Path: $TOn”;
if( $F2M_RECEIPT ) {
$headers .= “Disposition-Notification-To: $TOn”;
}
$upload_file = ( $_FILES[‘FilenameUpload’][‘name’] != “” );
if( ! $upload_file ) {
mail($TO, ‘=?UTF-8?B?’.base64_encode($SUBJECT).’?=’, $intro.”nn”.$message, $headers );
} else {
$FilenameUpload_name = $_FILES[‘FilenameUpload’][‘name’];
if( $LANG == “fr” ) {
$message .= “nFichier joint = “;
} else
$message .= “nAttached file = “;
if( $UPLOADMODE == 0 ) {
$HREF = substr( $HREF, 0, strrpos( $HREF, ‘/’ ) – 1 );
$HREF = substr( $HREF, 0, strrpos( $HREF, ‘/’ ) + 1 );
$message .= $HREF . “_iserv/form2mail/data/” . $_FILES[‘FilenameUpload’][‘name’];
} else
$message .= $_FILES[‘FilenameUpload’][‘name’];
$m = new Mail;
$m->From( $TO );
$m->To( $TO );
$m->Subject( $SUBJECT );
$m->Body( $intro.”nn”.$message );
$m->setReceipt( $F2M_RECEIPT );
$delete_upload = false;
if( $_FILES[‘FilenameUpload’][‘error’] == UPLOAD_ERR_OK ) {
if( $AUTHORIZED_EXT != “” && $FilenameUpload_name != “” && strpos( $AUTHORIZED_EXT, GetExtensionName( “$FilenameUpload_name”, true ) ) === false ) {
$error_code = -2;
} else {
$FilenameUpload_name = str_replace( ” “, “_”, $FilenameUpload_name );
$FilenameUpload_name = str_replace( “‘”, “_”, $FilenameUpload_name );
$FilenameUpload_name = str_replace( ‘”‘, ‘_’, $FilenameUpload_name );
$FilenameUpload_name = str_replace( ‘&’, ‘_’, $FilenameUpload_name );
$FilenameUpload_name = str_replace( ‘..’, ‘.’, $FilenameUpload_name );
preg_replace(“/[^0-9^a-z^_^.^-]/”, “”, $FilenameUpload_name);
if( !move_uploaded_file( $_FILES[‘FilenameUpload’][‘tmp_name’], “$upload_dir” . “$FilenameUpload_name” ) ) {
if( !copy( $_FILES[‘FilenameUpload’][‘tmp_name’], “$upload_dir” . “$FilenameUpload_name” ) ) {
$error_code = 9;
}
}
}
} else {
$error_code = $_FILES[‘FilenameUpload’][‘error’];
}
if( $error_code == “” && $UPLOADMODE > 0 ) {
$m->Attach( $upload_dir. “$FilenameUpload_name”, mime_content_type( “$FilenameUpload_name” ) );
$delete_upload = true;
}
if( $error_code == “” && $m->ErrMsg() != “” ) {
$error_code = $m->ErrMsg();
}
if( $error_code == “” ) {
if( $UPLOADMODE == 0 ) {
mail($TO, ‘=?UTF-8?B?’.base64_encode($SUBJECT).’?=’, $intro.”nn”.$message, $headers );
} else if( !$m->Send() ) {
if( “$FilenameUpload_name” != “” ) {
if( $LANG == “fr” ) {
$message .= “nnATTENTION: Le fichier joint n’a pas pu &#234;tre envoy&#233; par email mais il a &#233;t&#233; enregistr&#233; sur votre espace web.”;
} else {
$message .= “nnWARNING: The attached file could not be sent by email but is saved on your web space.”;
}
if( !mail($TO, ‘=?UTF-8?B?’.base64_encode($SUBJECT).’?=’, $intro.”nn”.$message, $headers ) ) {
$error_code = “-1”;
} else
$delete_upload = false;
}
else {
$error_code = “-1”;
}
}
}
if( $delete_upload ) {
Unlink( $upload_dir . $FilenameUpload_name );
}
}
}
if( $error_code != “” ) {
if( $error_code == “-1” ) {
$error_code = “Mail server error.”;
} else if( $error_code == “-2” ) {
$AUTHORIZED_EXT = str_replace( “|”, “,”, $AUTHORIZED_EXT );
$AUTHORIZED_EXT = strtoupper( str_replace( “.”, ” “, $AUTHORIZED_EXT ) );
if( $LANG == “fr” ) {
$error_code = “Type de fichier non accept&#233;. Votre fichier doit &#234;tre au format:” . $AUTHORIZED_EXT . “.”;
} else
$error_code = “Type of file not accepted. File format must be:” . $AUTHORIZED_EXT . “.”;
} else if( $error_code == “1” || $error_code == “2” ) {
if( $LANG == “fr” ) {
$error_code = “Votre fichier est trop gros. La taille maximale autoris&#233;e est ” . $MAXFILESIZE. ” Ko.”;
} else
$error_code = “File is too big. Maximum size is ” . $MAXFILESIZE . ” KB.”;
} else if( $error_code == “3” || $error_code == “9” ) {
$error_code = “Upload of the attached file failed (error “.$error_code.”).”;
} else if( $error_code == “4” ) {
$error_code = “Attached file is empty.”;
} else
$error_code = “ERROR “.$error_code . “: “;
echo “<script language=”javascript” charset=”utf-8″>window.location=’javascript:history.back()’;alert(‘$error_code’);</script>”;
} else if( $URL != “” ) {
redir(“$URL”);
}
?>

[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@mavigozlerJul 05.2012 — So you don't want the form user to specify the subject.

Here are changes I might make, although it is usually hard to modify someone's undocumented/uncommented code.

Line 7: $SUBJECT = "";

Between the quotes, enter the text you want to appear as the hardcoded subject.


Lines 19 and 20:

Put at the beginning of these two lines two successive forward slash characters: //

See if that does what you want.
Copy linkTweet thisAlerts:
@OptimisticauthorJul 07.2012 — Thank you ever so much for taking the time to help me out.

Thank works fine - thank you again!!
×

Success!

Help @Optimistic 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...