PHP mail() function hosted on iPage [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
<?php
$su="";
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];
$to='jikkas#gmail.com';
$subject = 'the subject';
$message = 'Subject: '.$subject.'</br></br></br>'.$message;
$headers = 'Name: '.$name.'</br>'.'Email: '.$email;
$send= mail($to, $subject, $message, $headers);
if ($send)
{
$su="Thanks for being with us...";
}
}
?>
This my email function. But it's not working. My site is hosted on ipage server.

For starters, your code needs tidying up, so I have done this for you. Also, what do you mean it's not working? You won't know if it is working because you haven't told it to tell you. You have just set the variable $su and not done anything with it. Here is what your code should look like:
<?php
$su="";
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'jikkas#gmail.com';
$subject = 'the subject';
$message = 'Subject: '.$subject.'</br></br></br>'.$message;
$headers = 'Name: '.$name.'</br>'.'Email: '.$email;
$send = mail($to, $subject, $message, $headers);
if($send)
{
$su = "Thanks for being with us...";
echo $su;
}
else
{
$su = "Error: unable to send";
echo $su;
//See note below
}
}
?>
I have included an else statement in there just as an example if you want to use your own error handling function. However, error_reporting should ideally be set to E_ALL to ensure you are capturing any errors that may be occurring. Also, ensure you have the correct mail settings in your php.ini. Look here for more details on mail settings in php.ini.
I would recommend running the following script:
<?php
// Set error reporting level to all errors
error_reporting(E_ALL);
// View php.ini and look for the mail settings
phpinfo();
?>
Hope this helps!

I think you had to create a Mail Account in the Panel.

Related

405 Not Allowed Github PHP

I hosted my website on github.My contact form doesn't work.I used PHP and HTML to make it.Here are my php code lines
PHP:
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$emailFrom = $_POST['email'];
$mobile = $_POST['number'];
$message = $_POST['message'];
$mailTo = "vukstamenkovic9#zohomail.eu";
$headers = "From: ".$emailFrom;
$txt = "You have received an e-mail from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsent");
}
?>
When I want to contact,I always get this: 405 Not Allowed
How can I resolve this?I searched it and nothing showed up.I would really appreciate help.

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 Sending Email Comma error [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I am having trouble with sending emails through PHP.
So I have a form which submits to a PHP script which sends an email:
<?php
$to = "myemail#email.com";
$subject = "[Contact Form]";
$name = $_POST["name"];
$contactNumber = $_POST["contactNumber"];
$email = $_POST["email"] ;
$message = $_POST["message"];
$body = "Someone has sent a new message from the contact form. \n \n Message from: " . $name . "\n Contact Number: ". $contactNumber ."\n Email: ". $email ."\n \n Message: ". $message;
if (mail($to, $subject, $body)) {
echo ("<p>Email successfully sent!</p>");
} else {
echo ("<p>Email delivery failed…</p>");
}
?>
And the email is sent fine when for example the message is one line such as:
"Hi there how is it going?"
And fine if it is multiple lines such as
"Hi there
how is it going?"
But when I try and type a message with a comma such as
Hello there,
how is it going?
It fails?
Is there a way I can just treat the whole thing as a string possibly? Would this also fail on any other characters or is this issue just because of the way I am writing the PHP script?
This might be an obvious fix but I am new to PHP so apologies! I have tried looking around for an answer but nothing seems to fix what I am looking for.
Thanks for any help!
Try using headers in your mail function, like this:
$headers = 'MIME-Version: 1.0\r\n';
$headers .= 'Content-type: text/html; charset=UTF-8\r\n';
mail($to, $subject, $body, $headers)

Tell a friend form not working

<?php
if ($_POST['friends-email']) {
$name = "Sender's Name";
$email = "sender#domain.com";
$recipient = preg_replace("/[^a-z0-9 !?:;,.\/_\-=+##$&\*\(\)]/im", "", $_POST['friends-email']);
$recipient = preg_replace("/(content-type:|bcc:|cc:|to:|from:)/im", "", $recipient);
$mail_body = "Default Description";
$subject = "Default Subject";
$header = "From: " . $name . " <" . $email . ">\r\n";
mail($recipient, $subject, $mail_body, $header);
echo 'Thank you for recommending <br /> us!';
} else {
echo '<form action="" method="post" name="send2friend" id="send2friend">
Friends Email*:
<input name="friends-email" id="friends-email" type="text" />
<input type="submit" value="continue" />
</form>';
}
?>
Not sure why this isn't working, I get the "thank you message" but the email is not delivered when I test using my own emails.
Just stating the obvious, but where you have put $email = "sender#domain.com";, you are actually changing that to a variable right?
Do you have all PHP errors turned on and displaying?
error_reporting(E_ALL);
ini_set('display_errors', '1');
Use PHP interactive mode (php -a)to deploy an email
$to = 'dummymailing#mailinator.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster#example.com' . "\r\n"; mail($to, $subject, $message, $headers);
Then go here to check that it's received. This is just to check that it's not a problem with your email client - i.e. it's not blocking the email.
If you're still having problems, it could be something to do with the system's sendmail function. This post on serverfault provides a lot of detailed advice on debugging the sendmail function.
Have you tried the mail function with hardcoded values, to check phpmail is set up right?
Then if that works, replace each value one at a time, and you will find your bug. I am guessing it is you regular expression replace however.
Try enclosing the mail delivery in an if statement

PHP mail() function not using "from" address [duplicate]

This question already has answers here:
How to change envelope from address using PHP mail?
(6 answers)
Closed 8 years ago.
$to = "me#mydomain.com";
$subject = "Auction Registration Confirmation";
$from = "From: donot-reply#mydomain.com";
$body = "Test Message";
if (mail($to, $subject, $body, $from)) {
echo("<b>Message sent</b>");
header( "Location: http://www.mydomain.com/thankyou.html" );
} else {
echo("<b>Message failed</b>");
}
Now the problem is that when an email is sent, the from address is not what I require, but the server login name.
Any ideas as to replace the server login name with the from email id.
YOu could try
mail($to, $subject, $body, $from, "-f $from");
this works in some configurations, really depending on the server setup.
Otherwise, edit your MTA settings as recommended above, or skip mail() altogether and use a class like PHPmailer that connects directly to the SMTP server.
There doesn't look to be anything wrong with your PHP code - I have very similar code doing the same job and it works fine.
Possibly there's something misconfigured with your email setup?
The PHP mail function relies on the MTA running on your server. I would bet that your MTA is setup to force the $from variable to your login name.
did you try this? it works for me fine
<?php
$to = "email#to.com";
$subject = "subject";
$message = "message";
$from = "email#from.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Categories