php: send email when ftp-upload was a success? - php

i wonder what i'm doing wrong? I'm working on a ftp-upload with php. if files are uploaded successfully i want to get a confirmation email. just a simple email.
if my connection to the FTP Server was a success i'm calling the sendmail() function! it's not working!
function sendmail() {
$EmailFrom = "do-not-reply#mypage.com";
$EmailTo = "myemail#mypage.com";
$Subject = "File uploaded to your FTP Server";
$Body = "Howdy, files have just been transferred to your Server.";
// Email Headers with UTF-8 encoding
$email_header = "From: " . $EmailFrom . "\r\n";
$email_header .= "Content-Type: text/plain; charset=UTF-8\r\n";
$email_header .= "Reply-To: " . $EmailFrom . " \r\n";
$success = mail($EmailTo, $Subject, $Body, $email_header);
if ($success){
print "success with EMAIL";
}
else{
print "error with EMAIL";
}
}
any idea what i'm doing wrong here? does the $EmailFrom value have to be an actual Emailaddress? It's just not working. Neither success nor error gets printed out. And nothing of my code AFTER the function-call gets executed.
thank you for your help

Well if you want to sendmail() when ftp upload is success do something like this
$status = move_uploaded_file($src,$destination);
if($status) { sendmail(); }
What this will do this, first $status will hold the boolean value whether the upload is successful, and if it suceeds then it will call your sendmail() function

Related

Having an issue using mailer.php

I'm currently using a mailer.php file for a minimal contact form
However I have noticed recently then when submitting the form, I am getting the following error;
HTTP Error 405.0 - Method Not Allowed
The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.
My mailer.php file is the following
<?php
$email_to = "admin#mydomain.co.uk";
$name = $_POST["name"];
$email_from = $_POST["admin#mydomain.co.uk"];
$message = $_POST["message"];
$email_subject = "Feedback from website";
$headers = "From: " . $email_from . "\n";
$headers .= "Reply-To: " . $email_from . "\n";
$message = "Name: ". $name . "\r\nMessage: " . $message;
ini_set("sendmail_from", $email_from);
$sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from);
if ($sent)
{
header("Location: https://www.mydomain.co.uk/thankyou.html/");
} else {
echo "There has been an error sending your message. Please try later.";
}
?>
The form using this file has the following form tag
<form method="post" action="mailer.php">
PHP is not my strong point so I'm not sure why this maybe happening. The form itself does not have a captcha field. Could spam be the root of the issue?
I'd appreciate anyone who can shed this light on this for me

Why the mail content sent are the raw html codes?

Mail content:
<html><head></head><body><p> Message : 鏽嫌╒杜米土 杯屎</p>Share Link : Press here to enter <br><img src ='http://203.80.1.28/FlippingBook/development/demo/medium/Web081112_P070_medium.jpg' /></body></html>
PHP:
if (isset($_POST["data"])){
$info = explode("&", $_POST["data"]);
$headers = 'MIME-Version: 1.0\r\n';
$headers .= "Content-Type: text/html; charset = \"UTF-8\";\n";
$headers = "From: =?UTF-8?B?" . base64_encode(substr($info[0],strpos($info[0],'=')+1, strlen($info[0]))) . "?=";
$to = substr($info[1],strpos($info[1],'=')+1, strlen($info[1]));
$subject = "=?UTF-8?B?" . base64_encode('日報分享') . "?=";
$message = trim(substr($info[2],strpos($info[2],'=')+1, strlen($info[2])));
$message = '<html><head></head><body><p> Message : '.$message;
$url = substr($info[3],strpos($info[3],'=')+1, strlen($info[3]));
$message = $message. '</p>Share Link : Press here to enter ';
if (isset($info[4])){
$firstImg = substr($info[4],strpos($info[4],'=')+1, strlen($info[4]));
$message = $message."<br><img src ='".$firstImg."' />";
}
if (isset($info[5])){
$secondImg = substr($info[5],strpos($info[5],'=')+1, strlen($info[5]));
$message = $message."<br><img src ='".$secondImg."' />";
}
$message = $message.'</body></html>';
if (mail($to, $subject, $message, $headers))
die ('Mail sent');
else
die ('Fail');
}else{
die ('Fail');
}
I am writing a simple program to send email. However, my mail content is not english based so I used utf-8 to encode.
When I changed the encode method, it can not send the processed html code, instead the mail content is the raw html code shown above, how to fix this problem?
If using PEAR lib is not a problem than you can look for Pear Mail-Mime lib to send mail or HTML contents. More details you can get from here - http://pear.php.net/manual/en/package.mail.mail-mime.example.php

Warning: mail() [function.mail]: SMTP server response: 550 Invalid recipient:

I'm creating a 'forgot password' page where the user enters their email address and the script finds the password associated to that email, and sends it to the stored email address.
I believe the problem has to do with my SMTP Mailserver. I am using WAMP which doesn't have one so I downloaded one that was free.
This is the php script I'm using:
$id = checkEmail($email);
$record = readMemberRecord($id);
$password = #mysql_result($record,0,'cred');
if($password){
$email_subject = "Email Request";
$email_body = "Your password is ".$password.".";
$header = "NinjaMan";
mail($email, $email_subject, $email_body,$header);
$msg = "Your password has been sent to ".$email.".";
}else{
$msg = "Sorry, the email ".$email." wasn't found.";
}
The $msg outputs properly so I know the code is passing the mail function.
Try sending in a proper "From" in $header.
$emailFrom = "admin#yourdomain.com"; // match this to the domain you are sending email from
$email = "example#example.com";
$subject = "Email Request";
$headers = 'From:' . $emailFrom . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-path: " . $email;
$message = "Your password is ".$password.".";
mail($email, $subject, $message, $headers);
See details of the mail() function.
If this doesn't work, try using PHPMailer. You configure it in code, no need to edit php.ini.
I've used it in some projects (v 2.0.4, I see the latest is 5.1) and had no problems.
Try using Google's server to send mails, you can see how to do that here
Try using this
//Email information
$to = "garggarima#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a test email message.";
$from = "support#sltechsoft.com";
$headers = "From:" . $from;
$mail=mail($to,$subject,$message,$headers);
if($mail) {
echo "Thanks for mail";
} else {
echo "Mail not Sent";
}
//Email response
echo "Thank you for contacting us!";

PHP Contact Form not Sending?

Ive got a contact form that isnt sending but is outputting that the message is sent? Can anybody see a problem?
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = "myemail#email.co.uk";
//begin of HTML message
$message = "
From : $name,
Email: $email,
Subject: $subject,
Message: $message ";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Website Enquiry";
if (isset($_POST['name'])) {
// now lets send the email.
mail($to, $subject, $message, $headers);
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=Thankyou, we will be in touch shortly.');
} else {
header('Location: ' . $_SERVER['HTTP_REFERER'] . '?e=There was an error sending your message, Please try again.');
}
?>
The "From" header should have a syntactically correct email address. You also need to check the return value of the "mail" function.
$header .= "From: Website Enquiry <enquiry#website.com>";
PS: Please improve your code formatting.
Try to enter an email at From: in $headers.
Like $headers .= "From: youremail#provider.com" or
$headers .= "From: Website Enquiry <youremail#provider.com>"
And you should change it to
if(mail(...)) {
//success
}
else {
//email failed
}

Error implementing AJAX/PHP/HTML5 form

I'm trying to solve this puzzle here. The contact form on this page (http://www.b3studios.co.uk/) uses AJAX and PHP. I copied all the code and trying to make it work (reverse engineering PHP). I'm not sure how the PHP file should look like to handle the data given by AJAX. I tried the following PHP file:
<?php
$sender = $email;
$receiver = “test#email.com”;
$email_body = “Name: $name \nEmail: $email \nMessage: $message”;
if( mail( $receiver, $subject, $email_body, “From: $sender\r\n” .
“Reply-To: $sender \r\n” . “X-Mailer: PHP/” . phpversion()) )
{
echo “Success! Your message has been sent. Thank You.”;
}
else
{
echo “Your message cannot be sent.”;
}
?>
After pressing "Send Message" it gets stuck at sending message....
Any suggestions to troubleshoot would be greatly appreciated.
I am pretty sure you copied the code with those ugly double quotes “ (MSWord quotes), you should chage to "
try
<?php
$sender = $email;
$receiver = "test#email.com";
$email_body = "Name: $name \nEmail: $email \nMessage: $message";
if( mail( $receiver, $subject, $email_body, "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion()) )
{
echo "Success! Your message has been sent. Thank You.";
} else {
echo "Your message cannot be sent.";
}
?>

Categories