Ive got the following php code:
<?
if ($_POST['emailme']) {
$yemail = $_POST['email'];
$host = $_SERVER['HTTP_HOST'];
$email = "<autoreply#$host>";
if (mail('$yemail', 'This is a Subject', 'This is the body of the email', 'From: $email')) {
echo "Message sent!";
} else {
echo "Message failed sending!";
}
}
?>
This is my HTML:
<FORM METHOD="POST" ACTION=""><INPUT TYPE='TEXT' CLASS='BOX' NAME='email' /><INPUT TYPE='SUBMIT' NAME='emailme' CLASS='SUBMITBOX' VALUE='Send!' /></FORM>
Any ideas why its not sending the email ? it says Message Sent but im not receiving any emails in my inbox
All help is much appreciated, thanks
PS: ive tried the following (with double quotes):
if (mail("$yemail", "This is a Subject", "This is the body of the email", "From:" . $email)) {
echo "Message sent!";
} else {
echo "Message failed sending!";
}
but still no luck
try this
if (mail('akh40#hotmail.co.uk', 'This is a Subject', 'This is the body of the email', 'From:'. $email))
Apparently most hosting companies are dropping support for php's mail() function in favour of SMTP versions of email scripts.
See http://www.thesitewizard.com/php/protect-script-from-email-injection.shtml for an explanation of why.
Try this for an SMTP/SSL script:
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender#example.com>";
$to = "Ramona Recipient <recipient#example.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://mail.example.com";
$port = "465";
$username = "smtp_username";
$password = "smtp_password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
Related
I am using Php Pear mail for sending an attachment to the user who fills out a form. If I hard code the "to email" address it works fine. But when I use
$to = $_POST['email'] ; I get the following error.
Failed to add recipient: #localhost [SMTP: Invalid response code received from server (code: 501, response: <#localhost>: no local part)]
<?php
require_once 'Mail.php';
require_once 'Mail/mime.php';
$from = "email#domain.com";
$to = $_POST['email'] ;
$subject = 'Free Diagnostic Test Coupon';
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
$text = 'Please find attached the coupon';// text and html versions of email.
$html = '<html><body>Please find attached the coupon</body> </html>';
$file = 'img/coupon.jpg'; // attachment
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'image/jpeg');
//do not ever try to call these lines
$host = "host";
$username = "username";
$password = "password";
in reverse order
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true,
'username' => $username,'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
}
else {
echo("<p>Message successfully sent!</p>");
}
?>
Any help will be appreciated.
Check your code by adding the top of it.
error_reporting(E_ALL); ini_set('display_errors', '1');
I have the following code that sends an email properly, but the email is received with a FROM value of root#mysite.com . I would like to have the value of the received email FROM be the value email (that is entered in a contact form) so that the received email can be replied top easily. Any assistance would be appreciated.
Thanx
<?php
if ($_POST["email"]<>'')
{
require_once "Mail.php";
$from = "root#mysite.com";
$to = "info <info#mysite.com>";
$subject = "Contact us info from Website";
$body = "Name: ".$_POST["name"]."\r\n";
$body .= "Email: ".$_POST["email"]."\r\n";
$body .= "Phone: ".$_POST["phone"]."\r\n";
$body .= "Comment: ".nl2br($_POST["comment"])."";
$host = "mail.mysite.com";
$username = "root#mysite.com";
$password = "abcdefghijk";
$headers = array ('From' => $from,'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body, "FROM: $email","-f$replyToEmail");
mail("$toEmail", $subject, $message, "FROM: $fromEmail","-f$replyToEmail");
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
Just set
$from = $_POST['email'];
You do it like this.
$fromEmail= 'From:'.$_POST["email"];
use $fromEmail in your mail function.
I'm having trouble getting an email address from $_GET.
Here is my code:
<?php
$eadd = $_GET['email'];
echo("<p>Please check your inbox on your email $eadd.</p>");
?>
I went to this link:
http://localhost/file.php?email=myemail#company.com
Yet the output is only:
Please check your inbox on your email .
EDIT
Here's my complete code :
<?php
require_once "Mail.php";
//Get link posted info's needed
//Email
$eadd = $_GET['email'];
$from = "OtakuJam Registration <no-reply#comp.com>";
$to = " $unick < $eadd >";
$subject = "Thank you for registering";
$body = "Dear $unick ,
\n Thank you for registering to OtakuJam. To activate your account, \n
";
$host = "mail.srv.com";
$username = "name#comp.com";
$password = "mypass";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Please check your inbox on your email $eadd.</p>");
}
?>
`Please ignore the $unick there, also the mail won't send unless i put an email on the code instead of < $eadd >
turning my $to syntax to $to = $unick . "<" . $eadd . ">"; as #Charlie gave me helped me. Also to those who told me to use ".$variable.". to my echo helped. thanks
I got a contact form that succesfully sends emails to me.
heres the extract:
$_POST['message'] = wordwrap($_POST['message'], 70);
mail ('myemail#test.com', $_POST['subject'], $_POST['message'] , $_POST['email']);
echo "<div class='registertext'>Your email was succesfully sent to a member of the administration team. Please wait 24 hours for as to reply and ensure you check your junk mail!<br />To login please click <a href='login.php'>here</a></div>";
The issue I have is, the email gets sent from my host. Not a email I want to specify. How would I overcome this?
You can specify it in the email headers:
$recipient = "recipient#test.com";
$from = "You#yoursite.com";
$replyTo = "You#yoursite.com";
$subject = "Hi!";
$text = "<p>This is a test!<p>";
$headers = "MIME-Version: 1.0\r\n"
."Content-Type: text/html; charset=utf-8\r\n"
."Content-Transfer-Encoding: 8bit\r\n"
."From: =?UTF-8?B?". base64_encode([Your Name]) ."?= <$from>\r\n"
."Reply-To: $replyTo\r\n"
."X-Mailer: PHP/". phpversion();
//send it!
if (mail($recipients, $subject, $text, $headers, "-f $from")){
echo "sent";
} else {
echo "did not send";
};
but there's a good chance it will get caught be SPAM filters. Your best bet in this case would be to use a PHP mailing library that handles SMTP emailing and uses your actual account to send mail (there are several packages that can handle this for you: Pear Mail, and PHP Mailer amongst others.
You can use PEAR mail which will use a SMTP account. Here is some code from my mail form I use
$from = "Name <webmaster#domain.com>";
$to = "Name <address#domain.com>";
$subject = "Subject";
$body = 'A message!';
$host = "ssl://domain.com";
$port = "465";
$username = "username";
$password = "password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
This code is working fine in my unix shared hosting account but how do I attach file with it?
I've removed the hostname, login, passwd etc.
<?php
require_once "Mail.php";
$from = "contactus#site.com";
$to = "to email id";
$subject = "this is the message from your domain";
$body = "give your message body here";
$host = "mail.site.com";
$username = "user";
$password = "pass123";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) { echo("" . $mail->getMessage() . "");
} else {
echo("Message Sent successfully ");
}
?>
You have to include both PEAR::Mail and PEAR::Mail_Mime, as it takes both classes to get the full email sent. Example...
include_once('Mail.php');
include_once('Mail_Mime/mime.php');
// include_once('Mail/mime.php');
// The code below composes and sends the email
$message = new Mail_mime();
$message->setTXTBody($text);
$message->addAttachment($path_of_attachment_file);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);