not receiving attachments using php pear package on linux based server - php

Following is my code for sending attachments.
Any help is useful.enter code here
Thanks in advance.
send_attach.php
<?php
#include_once 'Mail.php'
#include_once 'Mail/mime.php' ;
$hdrs['email'] = $mime;
$headers['To'] = $work_mail;
$headers['Subject'] = "Application For Job";
$headers['Content-type'] = "text/html; charset=windows-1251";
$headers['MIME-Version'] = "1.0";
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = '/studylink.txt';
$crlf = "\n";
$hdrs = array(
'From' => 'me#here.com',
'Subject' => 'Test mime message'
);
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');
$body = $mime->get();
$body=$mime->get(array('html_charset'=>'windows-1251','text_charset'=>'windows-1251','head_charset'=>'windows-1251'));
$hdrs = $mime->headers($hdrs);
#$mail =& Mail::factory('mail');
#$mail->#$mail->send('there#somewhere.com', $hdrs, $body);
?>
send_file.html
<form action="send_attach.php" method="post" enctype="multipart/form-data">
<table width="35%" border="0" align="center" cellpadding="0" cellspacing="6">
<tr class="style14">
<td width="16%">Name <span class="style8">*</span></td>
<td width="84%"><input type="text" placeholder="Name" name="name" id="name" for='name'></td>
</tr>
<tr class="style14">
<td>Email <span class="style8">*</span></td>
<td> <input type="text" name="email" id="email" for='email' placeholder="Email"> </td>
</tr>
<tr class="style14">
<td>Phone</td>
<td> <input name="phone" type="text" id="phone" for='phone' maxlength="10" placeholder="Numbers Only"></td>
</tr>
<tr class="style14">
<td valign="top">Employment <br />
Eligibility <span class="style8">*</span></td>
<td valign="middle">
<select name="work" class="style14" id="work">
<option selected="selected">--- select option ---</option>
<option>a</option>
<option>b</option>
<option>c`enter code here`</option>
</select> </td>
</tr>`enter code here`
<tr class="style14">
<td>Experience<br />
Summary <span class="style8">*</span></td>
<td valign="middle"><textarea name="summary" cols="35" rows="2" id="summary" placeholder="Experience Summary"></textarea></td>
</tr>
<tr>
<td valign="top" class="style14">Resume<span class="style8"> * </span></td>
<td><label>
<input name="attachment" type="file" for='resume_uploaded_file'>
</label></td>
</tr>
<tr>
<td> </td>
<td><input type="reset" name="Reset" id="button" value="Reset" />
<input type="submit" name="btn_get" id="btn_get" value="Submit" /></td>
</tr>
</table>
</form>

It doesn't look like you've uploaded the file to the filesystem in the example you provided. You need to process the upload from the form POST, put the file on the filesystem, and then make sure you are referencing it correctly when you add it. /file looks at the root of the server, not of the web server where your website is.
If you do a file_exists('/studylink.txt')
...My guess is the file does not exist.

Related

when press submit the page reloading as the php file

I have some problem with my form...
When I press the submit button the page not only doesn't send the mail, it also reloading the page and show the php file at a text all over the website... Someone know how to fix that please?
Thank you all!
The form part from the HTML:
<form action="mail.php" method="post">
<table class="table">
<tbody>
<tr>
<td rowspan="2" width="50%">
<div class="cart-total">
<strong class="cart-total-title">סך הכל</strong>
<span class="cart-total-price">0₪</span>
</div>
</td>
<td align="right" width="25%">
<input type="text" name="inpPhone" size="10" required></input>
:טלפון
</td>
<td align="right" width="25%">
<input type="text" name="inpName" size="10" required></input>
:שם מלא
</td>
</tr>
<tr>
<td align="right" width="25%">
<input type="text" name="inpCity" size="10" required></input>
:עיר
</td>
<td align="right" width="25%">
<input type="text" name="inpAddress" size="10" required></input>
:כתובת
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input type="date" name="inpDate" required></input>
:תאריך אספקה (ניתן להזמין עד יומיים לפני)
</td>
</tr>
<tr>
<td colspan="3" align="right">
</br>
אם הוזמנו מארז עוגיות/עוגת שמרים, יווצר עמך קשר בהמשך לגבי בחירת עוגיות/עוגה *
</td>
</tr>
</tbody>
</table>
<input type="submit" class="btn btn-primary btn-purchase" name="submit">להזמנה</button>
</form>
PHP:
<?php
if (isset(_POST['submit'])) {
$subject = "הזמנה חדשה";
$name = $_POST['inpName'];
$phone = $_POST['inpPhone'];
$city = $_POST['inpCity'];
$address = $_POST['inpAddress'];
$mailTo = "sappati#outlook.com";
$headers = "From:".$name;
$txt =
"התקבלה הזמנה חדשה! אלו פרטי ההזמנה:\n".
"שם: ".$name."\n".
"טלפון: ".$phone."\n".
"עיר: ".$city."\n".
"כתובת: ".$address."\n";
mail($mailTo, $subject, $txt, $headers);
}
?>
It's the native behavior of server side languages to reload to handle the request, if you want to make requests to server side, then you should use XMLHttpRequest or fetch or any other library for making requests
And about the php file being served as text, you should have apache or any other server install on your local machine to be able to handle server side code

Internal Server Error With Minimal PHP Contact Form

This site is hosted on shared hosting, unfortunately, the only thing the host seems to make available is the access log, not the PHP error log, so I'm having trouble figuring out the specific error here.
I'm trying to do a very minimal, simple contact form in PHP, without much validation or complexity. Getting a 500 error, though I'm sure I'm overlooking something basic.
Any assistance greatly appreciated.
HTML:
<form name="htmlform" method="post" action="collins_contact.php">
<table width="450px" cellpadding="20px">
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="first_name">First Name</label>
</td>
<td valign="top">
<input type="text" name="first_name" maxlength="50" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="last_name">Last Name</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="email">Email Address</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="telephone">Telephone</label>
</td>
<td valign="top">
<input type="text" name="phone" maxlength="30" size="30">
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="left">
<label for="comments">Questions / Comments</label>
</td>
<td valign="top">
<textarea name="message" maxlength="1000" cols="25" rows="6"></textarea>
</td>
<tr><td> </td></tr>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Submit">
</td>
</tr>
<tr><td> </td></tr>
</table>
</form>
PHP
<?php
if (isset($_POST["first_name"]) && isset($_POST["email"]) && isset($_POST["message"])) {
$name = $_POST["first_name"];
$email = $_POST["email"];
$subject = "Contact Form Submission";
$message = $_POST["message"];
$header = "from: $name <$email>";
$to = "contact#domain.com";
if (mail($to, $subject, $message, $header)) {
header("Location: index.html");
} else {
echo("Error With Form Submission");
}
}
?>
Permissions needed to be changed to 0644 on the php file, then it worked.

contact form not work in include function in php [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am including my contact form in index.php
in index.php
left.php code is
html code
<form action="" enctype="multipart/form-data" method="post">
<div align="left">
<table border="0" cellpadding="0" cellspacing="0" hspace="0" vspace="0" width="100%">
<tbody>
<tr>
<td class="fth" height="20" valign="middle"></td>
</tr>
<tr>
<td class="ft">* Name:</td>
</tr>
<tr>
<td class="ft"><input name="author" id="name" class="text" required="true" valtype="name" type="text" maxlength="25" placeholder="Enter Your Full Name" pattern="^[a-zA-Z -]+$"></td>
</tr>
<tr>
<td class="ft">* Phone:</td>
</tr>
<tr>
<td align="left" valign="top" class="ft">
<input name="mobile" id="phone" class="text" size="20" valtype="phmob" required="true" type="text" maxlength="12" placeholder="Enter 10 Digit Mobile Number" pattern="[789][0-9]{9}">
<span class="style3">eg : 9795042637</span></td>
</tr>
<tr>
<td class="ft">* E-mail:</td>
</tr>
<tr>
<td class="ft">
<input name="email" id="email" class="text" valtype="email" required="true" type="text" maxlength="55" pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$" placeholder="Enter Your Email Address">
</td>
</tr>
<tr>
<td class="ft">*Write your message:</td>
</tr>
<tr>
<td class="ft">
<textarea name="msg" id="msg" cols="25" rows="3" class="text" valtype="msg" nameinerr="Message" required="true" onkeypress="return preventCopy.disableCtrlKeyCombination(event, this);" onkeydown="return preventCopy.disableCtrlKeyCombination(event, this);" oncontextmenu="return false;" onmousedown="return preventCopy.rightClick(event,this);"></textarea>
</td>
</tr>
<tr>
<td class="ft">
<label for="home_loan"><input id="home_loan" class="home_loan" name="home_loan" value="Yes" type="checkbox">I am interested in Home Loan</label>
</td>
</tr>
<tr>
<td class="ft" height="45">
<br>
<input class="submit" value="Send" type="submit" name="button">
<input class="submit" type="reset" name="reset" id="reset" value="Reset" />
</td>
</tr>
</tbody></table>
</div>
php code in same file
if(isset($_POST['button']))
{
ob_start();
$name=$_POST['author'];
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$msg=$_POST['msg'];
$home_loan=$_POST['home_loan'];
$to ='mysite#gmail.com';
//$to ='info#mysite.in';
$subject = 'Enquiry Through mysite HomePage';
$message ="
Name = $name\r\n
E-mail = $email\r\n
Mobile = $mobile\r\n
Message = $msg\r\n
Home loan = $home_loan";
$headers = "From: $name < $email >" . "\r\n" .
"CC:mysite#gmail.com";
$sendmail = mail($to,$subject,$message,$headers,"-from#mysite.com");
if($sendmail)
{
//header("location:thanks.html");
echo "<h4 style='text-align:center;color:red;'>Your enquiry has been sent.</h4>";
}
else
{
header("location:index.php");
}
}
It is working fine when running mysite.com/left.php
but when I use in include its not submit query where am wrong help me out
thanks
Try changing your form declaration from this:
<form action="" enctype="multipart/form-data" method="post">
to this:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" enctype="multipart/form-data" method="post">
Move the php code to the top of index.php. You're doing things before anything should be outputted. If index.php outputs anything before this runs, it fails.

How to Keep Data fields When Recaptcha is Invalid

My php contact form is working fine and I just need help on how to keep the data fields when recaptcha is incorrect or invalid. Where do I need to ad more script to accomplish this?
Thank you very much for any answers. I am still new at php. This is ALL IN ONE PAGE Called: CONTACTFORM.php
<?php
require_once('recaptchalib.php');
$publickey = "xxxxxxxxx";
$privatekey = "xxxxxxxx";
$error = false;
$message = '';
if (isset($_POST['send'])){
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid)
{
$error = true;
$message = 'Invalid Captcha Please try again';
}
if(!$error)
{
$emailTitle = 'Email from website!';
$emailAddress = 'peace#hotmail.com';
/* Gathering Data Variables */
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$nameField = $_POST['name'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$body = <<<EOD
<br><hr><br>
Email: $emailField <br />
Phone: $phoneField <br />
Name: $nameField <br />
Subject: $subjectField <br />
Message: $messageField <br />
EOD;
$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail("$emailAddress", "$emailTitle", "$body", "$headers");
$message = "Thank you! Your message has been sent.";
}
}
?>
<form id="form1" name="form1" method="post" action="contactform.php">
<table width="100%" border="0" cellspacing="6" cellpadding="0">
<tr>
<td align="right"><label for="email" class="titulos">Email: </label></td>
<td align="left"><input name="email" type="text" id="email" size="35" maxlength="50" />
*</td>
</tr>
<tr>
<td align="right"><label for="phone" class="titulos">Phone: </label></td>
<td align="left"><input name="phone" type="text" id="phone" size="35" maxlength="50" /></td>
</tr>
<tr>
<td align="right"><label for="name" class="titulos">Name:</label></td>
<td align="left"><input name="name" type="text" id="name" size="35" maxlength="30" />
*</td>
</tr>
<tr>
<td align="right"><label for="subject" class="titulos">Subject:</label></td>
<td align="left"><input name="subject" type="text" id="subject" size="35" maxlength="60" /></td>
</tr>
<tr>
<td align="right" valign="top"><label for="message" class="titulos">Message:</label></td>
<td align="left"><p>
<textarea name="message" cols="27" rows="5" id="message"></textarea>
*</p></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left">
<?php echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<tr>
<td align="right"><label for="reset"></label></td>
<td align="left"><label for="send"></label>
<input name="send" type="submit" id="send" onclick="MM_validateForm('email','','RisEmail','name','','R','message','','R');return document.MM_returnValue" value="Send Email" /> <label for="reset"></label>
<input type="reset" name="reset" id="reset" value="Reset form" /></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left" class="content">(*) Are Required fields</td>
</tr>
<tr>
<td colspan="2" align="center"><?php echo $message; ?>
</td>
</tr>
</table>
</form>
You could set it in the "value" attribute of your input fields. Something like
<input name="email" type="text" value="<?php echo (isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''); ?>" />

Recaptcha. Need some php script for integrating recaptcha to existing form. This may be a simple answer

I am not that experienced at html and php but I managed to create a contact form and php script for sending emails to my hotmail account and it has been working fine.
Now i wanted to add Recaptcha to that form and I did it successfully. But now I would like some help on the next topics:
I want to make recpatcha work with my form
when recaptcha is Incorrect I want to keep the information fields and Not send the email also Not show the "thank you your message has been sent".
only when recaptcha is Correct: send the email, clear the information fields, show "thank you message has been sent"
SORRY i FORGOT TO MENTION THIS SCRIPT IS ALL IN ONE PAGE CALL "CONTACTFORM.PHP"
And by the way, this is a She.
Thank you very much for your answers! If you can give some details for the answer would be great!!!
here I have my codes:
Any help will be very appreciate!
This is my php for sending my email:
<?php
if ($_POST['parse_var'] == "form1"){
$emailTitle = 'Email from my website!';
$emailAddress = 'myemail#hotmail.com';
/* Gathering Data Variables */
$emailField = $_POST['email'];
$phoneField = $_POST['phone'];
$nameField = $_POST['name'];
$subjectField = $_POST['subject'];
$messageField = $_POST['message'];
$body = <<<EOD
<br><hr><br>
Email: $emailField <br />
Phone: $phoneField <br />
Name: $nameField <br />
Subject: $subjectField <br />
Message: $messageField <br />
EOD;
$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail("$emailAddress", "$emailTitle", "$body", "$headers");
$sent = "Thank you! Your message has been sent.";
}
?>
<form id="form1" name="form1" method="post" action="contactform.php">
<table width="100%" border="0" cellspacing="6" cellpadding="0">
<tr>
<td align="right"><label for="email" class="titulos">Email: </label></td>
<td align="left"><input name="email" type="text" id="email" size="35" maxlength="50" />
*</td>
</tr>
<tr>
<td align="right"><label for="phone" class="titulos">Phone: </label></td>
<td align="left"><input name="phone" type="text" id="phone" size="35" maxlength="50" /></td>
</tr>
<tr>
<td align="right"><label for="name" class="titulos">Name:</label></td>
<td align="left"><input name="name" type="text" id="name" size="35" maxlength="30" />
*</td>
</tr>
<tr>
<td align="right"><label for="subject" class="titulos">Subject:</label></td>
<td align="left"><input name="subject" type="text" id="subject" size="35" maxlength="60" /></td>
</tr>
<tr>
<td align="right" valign="top"><label for="message" class="titulos">Message:</label></td>
<td align="left"><p>
<textarea name="message" cols="27" rows="5" id="message"></textarea>
*</p></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left">
<?php
if (isset($_POST['send'])) {
require_once('recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
echo "Please try again";
} else {
echo "Correct";
}
}
?>
<?php
require_once('recaptchalib.php');
$publickey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<tr>
<td align="right"><label for="reset"></label></td>
<td align="left"><label for="send"></label>
<input type="hidden" name="parse_var" id="parse_var" value="form1" />
<input name="send" type="submit" id="send" onclick="MM_validateForm('email','','RisEmail','name','','R','message','','R');return document.MM_returnValue" value="Send Email" /> <label for="reset"></label>
<input type="reset" name="reset" id="reset" value="Reset form" /></td>
</tr>
<tr>
<td align="right"> </td>
<td align="left" class="content">(*) Are Required fields</td>
</tr>
<tr>
<td colspan="2" align="center"><?php print "$sent"; ?>
</td>
</tr>
</table>
</form>
First of all learn PHP SESSIONS
Here your algorithm :
SHow your form with recaptcha (form.php)
Send your form to step2.php for checking recaptcha , if it's right, send email. If it's wrong, set email, phone, name, subject and message to a session (for example : $_SESSION["name"] = $_POST["name"];) (you have to start session with session_start(); , at top of step2.php) and redirect to your form page with a querystring. like this : form.php?error=r
CHeck r querystring at form.php. If there is, print an error
Wrong Rechaptcha and set all <input>'s default values to
$_SESSION values. ($_SESSION["name"])
IF YOU WANT TO DO IT WITH ONE PAGE (RECOMMENDED)
<?php
if ($_POST["submit"]) // If form submitted
{
// recaptcha control. If pass, record it to database, or send mail, or whatever you want.
}
?>
<form action="" method="POST">
<input value="<?php echo $_POST['name']; ?>" name="name" type="textbox">
<input type="submit" name="submit">
</form>

Categories