<?php
echo $this->Form->end(__('Submit'))
$to = "someone#hotmail.com"; $subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Hey guys need help here! I want when someone pressed the submit button, it saves and sends the details entered to the emails
You have to use like this.Make sure your button type is submit
<?php
if($_POST){
$to = "someone#hotmail.com"; $subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
?>
If you are still running WAMPServer then you are on a Windows PC.
Window does not come with a mail server, and the mail() function does little else other than pass a mail onto a mail server.
You will either need to install a mail server, they do exist for windows, but this is not a simple task for a beginner.
Alternatively, look at phpMailer which can be used to send mail and basically piggy backs an existing email account like one of your yahoo or gmail accounts
Try the below code,
<?php
if(isset($_POST['submit'])){ // check if submit button is pressed
$to = "someone#hotmail.com"; $subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
if(mail($to,$subject,$message,$headers))
echo "Mail Sent.";
else
echo 'Error while sending mail.';
}
?>
Related
For example, i only want the sender's email is from "anything#abc.com", if other email like "anything#cde.com" is not allow, only #abc.com is allowed. How should i do that?
let say $_POST['Sender']="anything#abc.com";
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $_POST['Sender'];
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
you should be able to just wrap it within an if statement:
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = $_POST['Sender'];
$headers = "From:" . $from;
if ($from === "anything#abc.com") {
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
You can use PHP's strstr function to strip the first part of the email off (everything before #) like so:
$from = strstr($_POST["Sender"], "#");
if($from == "#abc.com") {
// send mail
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
}
See http://php.net/manual/en/function.strstr.php for more information on the strstr function
I'm trying to create a HTML form, which will in the end send an e-mail using the folling PHP Code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$destinationemail = "myemail#domain.com";
$emailcontent = "Name: {$name}\n\nE-Mail: {$email}\n\nMessage: {$subject}\n{$message}";
$subject = "Contact from Domain.com";
$from = $email;
mail($destinationemail, $subject, $emailcontent) or die("Error!");
echo "Thank you $name!";
?>
The problem is, everytime i receive an e-mail, i get is as if being sent from a what i guess is the Webhost general e-mail.
htgkaylg#server776.web-hosting.net
<htgkaylg#server776.web-hosting.net>
dom 08/10/2017, 18:40
Você;
I would like it to be received something like this:
myemail#domain.com
<myemail#domain.com>
dom 08/10/2017, 18:40
Você;
Is it possible?
Thank you,
Vítor
You have to use the Header as 4th parameter in mail() function.
Add this line and change mail as follow:
$headers = "From:" . $from . "\r\n";
mail($destinationemail, $subject, $emailcontent, $headers) or die("Error!");
Ref. https://www.w3schools.com/php/func_mail_mail.asp
I'm fairly new to this but I've done all the digging I can do. When I submit this form rather than displaying the sender's email (which is what I want) it displays the webserver I'm using in the From part. I'm not sure what I need to put to make display anyone's email.
<?php
$email = $_POST['email'];
$recipient = "my#email.com";
$subject = "Email Notice";
$headers = 'From: '.$email."\r\n".
if(mail($recipient, $subject, $headers)){
header("Location: thankyou.html");
}else{
header("Location: sorry.html");
}
exit;
?>
I have static ip on my home computer.
I am using windows-7 with xampp .
I creat the code for sending mail
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail( $to, $subject, $message, $headers );
echo "Mail Sent.";
?>
but sir mail is not received at destination.
I thinks is it possible to send mail from my home computer using windows7 xampp??
plz answer
See your answer here http://www.c-sharpcorner.com/UploadFile/c8aa13/send-mail-on-local-host-via-mercury-with-xampp/
Or here https://www.google.ru/search?q=use+mercury+to+send+email
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!";