I have a pop up on my website that lets the user know that the email has been sent.
I want to change that to a nicer message via bootstrap (website is made from bootstrap)
Instead of a pop up message, I'd like a contexual background.
You can see them here: Contextual backgrounds
http://getbootstrap.com/css/#helper-classes
This is what the popup code looks like.
if(wp_mail($to, $subject, $msg, $headers, $attachments)) { echo
'The message was sent. Check your email inbox.'; } else {
echo 'The message was not sent!'; };
enter code here
What do I need to do to change it?
You can echo html code with PHP:
if(wp_mail($to, $subject, $msg, $headers, $attachments)) {
echo '<p class="bg-success">The message was sent. Check your email inbox.</p>';
}
else {
echo '<p class="bg-danger">The message was not sent!</p>'; };
}
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I am trying to get a contact form using the built in mail function to work but I'm running into some problems.
What I would like:
On clicking 'submit' the form is sent to defined emailadres.php.
If sent successfully, a confirmation message is displayed.
If not sent, an error message is displayed.
What is currently happening:
Confirmation message already shows on page load; regardless of form submission.
Mail is not sent.
Code I'm using:
if ($_POST["submit"]) {
mail ($to, $subject, $body, $from);
$sendErr = "Your message has been sent";
} else {
$sendErr = "Your message could not be sent";
}
I'm fairly new to all this so any help figuring out where my thinking stalls would be appreciated. If I need to post more parts of the form I will.
The code you are using does not even check if the mail was sent successfully, it only checks it the formular was submitted. mail() returns true if the mail was sent successfully, false if not. So you can check its return value:
if ($_POST["submit"]) {
$sent = mail ($to, $subject, $body, $from);
// Check here if the mail was sent or not
if ($sent) {
$sendErr = "Your message has been sent";
} else {
$sendErr = "Your message could not be sent";
}
}
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
So this is my code for sending an email. When I try to send an email i get right message, in this case "User Exist" and "Email is sent", but i can't receive an email. So can somebody find mistake and try to help me?
<form action="forgot2.php" method="post">
Enter you email ID: <input type="text" name="email">
<input type="submit" name="submit" value="Send">
</form>
error_reporting(0);
$email=$_POST["email"];
$Subject = "GOSPodin covek";
if($_POST['submit']=='Send')
{
mysql_connect('localhost','root','') or die(mysql_error);
mysql_select_db('login');
$query="select * from clanovi where email='$email'";
$result=mysql_query($query) or die(error);
if(mysql_num_rows($result))
{
echo "User exist";
}
else
{
echo "No user exist with this email id";
}
}
if(mysql_num_rows($result))
{
$code=rand(100,999);
$message="You activation link is: http://localhost/login_form/forgot.php? email=$email&code=$code";
mail($email, "Subject Goes Here", $message);
echo "Email sent";
}
else
{
echo "No user exist with this email id";
}
First of all, you need to check if the mail is actually sent:
if (mail($email, "Subject Goes Here", $message)) {
// then it's actually sent.
}
If mail() doesn't return false, then the mail was passed to your local mail server for delivery. Presume you already have a mail server set up on your local test box? If not, problem is obvious...
If PHP checks out OK and you still don't receive the mail (and it's not in your spam folders etc.), you need to investigate your server's mail logs for possible issues outside PHP.
...and for the love of code and all things sacred to debugging, do NOT use error_reporting(0); if you're actually trying to figure out what's wrong! (Error messages are kinda helpful for that.)
Are you sure your script is actually sending the mail?
Replace:
mail($email, "Subject Goes Here", $message);
echo "Email sent";
By:
if(#mail($email, "Subject Goes Here", $message)) {
echo "Email sent";
} else {
echo "Email not sent";
}
Assuming mail() does return true and that the email is a valid one, you want to make you have a valid smtp server configured in php.ini in the [mail function] section.
Just try
I use this works fine for me
$headers = 'From: support#example.com';
mail($payer_email, 'Tokens', "Thank you for purchase tokens $additional-message", $headers);
change this one.
$query="select * from clanovi where email='".$email."'";
I have a problem with my web host, I been trying to call the support but no answer yet, so I trying here
I have this simple PHP code that sends an mail to my gmail, the code works fine on my other hosting site, but on www.one.com the php just shows "Your email was sent." but there is no email send. I have set the permisions to 777 on the file, but no luck.
Is there anything i can do to fix this or is it an problem for my web host?
This is my code
<?php
$name = "MyName";
$email = "MyName#gmail.com";
$message = "This is a test";
$to = 'Myothermail#gmail.com';
$subject = 'the subject';
$message = 'FROM: '.$name.' Email: '.$email.'Message: '.$message;
$headers = 'From: www.mysite.se' . "\r\n";
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message, $headers); //This method sends the mail.
echo "<div class='alert alert-success alert_box'>Your email was sent.</div>"; // success message
}
else
{
echo " <div class='alert alert-error alert_box'>Your email address is invalid. Please enter a valid address.</div>";
}
?>
Your script shows that your email was sent because you're not actually checking anything. mail() returns true if successful and false otherwise so:
if(mail($to, $subject, $message, $headers)) { //This method sends the mail.
echo "<div class='alert alert-success alert_box'>Your email was sent.</div>"; // success message
} else
{
echo "<div class='alert alert-error alert_box'>Mail send problem.</div>";
}
}
else
{
echo " <div class='alert alert-error alert_box'>Your email address is invalid. Please enter a valid address.</div>";
}
Can you check the logs, or enable error reporting?
I am trying to send an email to myself when an error happens from filling out the php form instead of doing Print="Sorry an error happened"
$error = "ERROR HAPPENED".$order."\r\n";
$error_email = mail($to, $subject, $error, $headers2);
$mail = #mail($email, $subject, $confirmation, $headers2);
if ($mail) {
header("Location: http://www.test.com" );
} else ($error_email);
You're not using brackets after the else.
if($mail)
{
header("Location: http://www.test.com");
}
else
{
mail($to, $subject, $error, $headers2);
echo $error;
}
And you were never using echo $error so the error couldn't be printed.
Your code is a little unclear - and it helps if you ask a question...
However, I'd suggest using a logging framework for this, such as log4php; this includes an email option, so errors can get mailed to you, or you can write them to disk, or the OS log file.
Please be aware that email is totally insecure - it's easy to intercept them, and they are not encrypted. I hope you're not sending sensitive data in the $order variable.
Finally, your code is probably not doing what you want it to.
$error = "ERROR HAPPENED".$order."\r\n";
Build the error string (assuming $order is nicely printable).
$error_email = mail($to, $subject, $error, $headers2);
Send an email to $to. $error_email is now a boolean value.
$mail = #mail($email, $subject, $confirmation, $headers2);
Send an email to $email. Suppress errors. $mail is a boolean.
if ($mail) {
header("Location: http://www.test.com" );
if the mail was sent successfully (to $email), redirect the user.
} else ($error_email);
If the mail was not sent successfully, not sure what you're trying to do...
It's not a good idea to tie your application logic to the random "did I manage to send an email" success.
I encounter a very strange problem with ixwebhosting.
I am able to send email using the php mail() function with $subject = "test";
But if $subject = "testing of information send"; then i won't be able to receive any email
But actually "Mail sent!" was displayed in the php page.
if (!mail($email, $subject, $body, $from)) { echo "Error Sending Email!"; }
else
{ echo "Mail sent!"; }
Is it possible that the email is being classed as spam somewhere down the track? Are you able to get logs from the mailserver indicating whether mail gets sent?