Php email is never sent, i dont know why - php

the link is http://creeper9207.com/register.php?code=2&&mto=EMAIL ADRESS HERE
<?php
$to = $_GET['to'];
$subject = 'SixtyCraft Confirmation Mail';
$message = 'Confirm code: '. $_GET["code"];
mail($to, $subject, $message);
?>

Try this..
//Change $to =". $_GET["to"] ."; to $to = $_GET["to"];
<?php
$to = $_GET["to"];
$subject = 'SixtyCraft Confirmation Mail';
$message = 'Confirm code: '. $_GET["code"];
$headers = "From: your#example.com";
mail($to, $subject, $message, $headers);
?>

Remove the " . and . " on the first line.
Consider checking your PHP error log.
Your web page is probably unsafe. You should send the mail when the user creates their account or at least use $_SESSION instead of $_GET.

Related

POST Request coming up blank, why?

I have the following code saved as send.php:
<?php
$to_email = "person#gmail.com";
$subject = $_POST['subject'];
$body = "Hi, This is test email send by PHP Script";
$headers = "From: Me#myWebsite.com";
if ( mail($to_email, $subject, $body, $headers)) {
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
?>
The email sends if I navigate to https://myWebsite.com/Stuff/send.php
and make $subject = "something"
But if I set $subject to be a POST variable. It does not send the subject when I write this URL in the browser (as in, the email still sends but the subject is now blank):
https://myWebsite.com/Stuff/send.php?subject=notworking
To get both $_POST and $_GET you can use $_REQUEST which will work for both.
In your code replace
$subject = $_GET['subject'];
With
$subject = $_REQUEST['subject'];
If someone direct hit the URL in browser without paramter subject you can prevent them using
if(!empty($_REQUEST['subject']))
{
$to_email = "person#gmail.com";
$subject = $_REQUEST['subject'];
$body = "Hi, This is test email send by PHP Script";
$headers = "From: Me#myWebsite.com";
if ( mail($to_email, $subject, $body, $headers))
echo("Email successfully sent to $to_email...");
else
echo("Email sending failed...");
}
If you want to extract the values from the URL parameters then you need to use the $_GET
global variable to get the data like this,
<?php
$to_email = "person#gmail.com";
$subject = $_GET['subject'];
$body = "Hi, This is test email send by PHP Script";
$headers = "From: Me#myWebsite.com";
if ( mail($to_email, $subject, $body, $headers)) {
echo("Email successfully sent to $to_email...");
} else {
echo("Email sending failed...");
}
?>
Try it.
<?php
$to_email = "person#gmail.com";
$subject = (isset($_GET['subject']) && (!empty($_GET['subject']))?$_GET['subject']:"No Subject";
$body = "Hi, This is test email send by PHP Script";
$headers = "From: Me#myWebsite.com";
if ( mail($to_email, $subject, $body, $headers))
echo("Email successfully sent to $to_email...");
else
echo("Email sending failed...");
?>

PHP E-mail form - Define sender

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

PHP contact form with Freehostia

I cannot get this form to send if I use anything other than $from = 'From: . $email';. If I change it to anything else, it will not send. When it does send with this information, it comes in from .$email#mbox.freehostia.com.
What I would prefer is have the from email address be the email that was submitted in the form, so the receiver can respond without having to create a new email. I've searched everything and can't find an answer to this specific issue.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$from = 'From: . $email';
$to = 'info#resourcedmichigan.com';
$subject = 'ResourcED Career Submission';
$body = "From: $name\nEmail: $email\nPhone Number: $phone\nMessage: $message";
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
include("inc/header.php");
echo '<div class="container"><div class="spacer-top"><h3>Thank you for your interest in ResourcED! We will be in contact with you soon!</h3></div></div>';
include("inc/footer.php");
} else {
echo '<div class="container"><h3>Something went wrong. Go back and try again!</h3></div>';
}
}
?>
Variables will not be interpolated inside of single quotes and the concatenation operator is unnecessary.
$from = 'From: . $email';
should be
$from = "From: $email";
or
$from = 'From: ' . $email;

Php form: email copy to sender

I have a simple form. Basically trying to replicate share by email thought this would be sufficient. I'd like to send a copy of this email to the $email variable (Yeah that stripslashes might not be necessary), any ideas on how to do so? Came across bunch of posts through google but couldn't figure it out;
<?php
$EmailFrom = "admin#test.com";
$EmailTo = "admin#test.com";
$Subject = "Check out this video.";
$email = !empty($_POST['email']) ? Trim(stripslashes($_POST['email'])) : false;
$Body = "Take a look at this; youtubelink...";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
header('Location: /#');
?>
Just edit your script like this, the copy will be sent only if the original will:
<?php
$EmailFrom = "admin#test.com";
$EmailTo = "admin#test.com";
$Subject = "Check out this video.";
$email = !empty($_POST['email']) ? Trim(stripslashes($_POST['email'])) : false;
$Body = "Take a look at this; youtubelink...";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success)
mail($EmailFrom, $Subject, $Body, "From: <$EmailFrom>");
header('Location: /#');
?>
Just add another mail(); function
<?php
$EmailFrom = "admin#test.com";
$EmailTo = "admin#test.com";
$Subject = "Check out this video.";
$email = !empty($_POST['email']) ? Trim(stripslashes($_POST['email'])) : false;
$BodyReceiver = "Take a look at this; youtubelink...";
$BodySender = "You sent the following message " . $BodyReceiver . " to " . $EmailTo . ".";
$successReceiver = mail($EmailTo, $Subject, $BodyReceiver, "From: <$EmailFrom>");
$successSender = mail($EmailFrom, $Subject, $BodySender, "From: <no-reply#text.com");
header('Location: /#');
?>
or something like that...
As bozdoz suggested you might do it with Bcc, but then it will be a total copy of the original. You will not be able to change the sender email or the massage (for instance to "You sent the following massage ... to ..." and whatnot.

email address in from field on contact form not showing in email header as "from"

iv added the header field in the form code but when i receive the email, the "from" field in the email shows a garbled code and not the email address of the person who sent the message. This is my message processing code:
<?php session_start();
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'I removed my address for privacy on stack overflow';
$fromsubject = 'A message from your website';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $nome <$mail>\r\n";
$to = $youremail;
$mailsubject = 'Message received from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$fname.' '.$lname.'
Address: '.$address.'
'.$city.', '.$zip.', '.$country.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Subject: '.$subject.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you for your feedback. I will contact you shortly if needed.<br/>Go to <a href='/index.php'>Home Page</a>";
mail($to, $subject, $body);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, you have provided an invalid security code';
}
} else {
echo "You must write a message. </br> Please go to <a href='/contact.php'>Contact Page</a>";
}
?>
You declared your ^From: header` here:
$headers = "From: $nome <$mail>\r\n";
But it isn't used when you call mail()
mail($to, $subject, $body);
You need to pass $headers as fourth parameter. Else the headers won't take effect
mail($to, $subject, $body, $headers);
You haven't declared $nome anywhere in your code nor $mail in:
$headers = "From: $nome <$mail>\r\n";
And besides that, as this comment mentions, you didn't pass the header into the mail function. See the fourth parameter of the mail function.

Categories