HTML form PHP post to email - php

I'd like to make a form that posts data to my email.
I found the following code and it works fine except I didn't get any email from the form.
Here is the Php File
<?php
// Contact subject
$name ="$name";
// Details
$address="$address";
$id="$id";
$passport="$passport";
$issue="$issue";
$mula="$mula";
$tamat="$tamat";
$tel="$tel";
$select_dd="$select_dd";
$date="$date";
$textarea="$textarea";
$file="$file";
// Mail of sender
$email="$email";
// From
$header="from: $name <$mail>";
// Enter your email address
$to ='rodhiahazzahra#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}?>

Where did you try this code? Local or on a Server? Is there sendmail (or similar) installed and properly configured on your server?
Quote from PHP - Mail Function
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
You should check your configuration on the server and check the mail logs and you spam-folder.

If i am not mistaken, you need to set the SMTP server before you call mail().
ini_set('SMTP','mySMTP.serv');
Cheers
Edit:
Caution
(Windows only) When PHP is talking to a SMTP server directly, if a full stop is found
on the start of a line, it is removed. To counter-act this, replace these occurrences
with a double dot.
<?php
$text = str_replace("\n.", "\n..", $text);
?>
If you just started learning, one of the basic rules is always RTM before you start using a function. here is the link for PHP Mail function http://us3.php.net/manual/en/function.mail.php

Related

E-mail piping with e-mail forwarder does not work

I have a simple email pipe script. But I need a copy of the incoming e-mail going to another e-mail address. Unfortunately I do not receive the e-mail as I wanted.
The code;
#!/usr/bin/php -q
<?php
$email_msg = ''; // the content of the email that is being piped
$email_addr = 'sales#flensmuts.nl'; // where the email will be sent
$subject = 'Piped:'; // the subject of the email being sent
// open a handle to the email
$fh = fopen("php://stdin", "r");
// read through the email until the end
while (!feof($fh)){
$email_msg .= fread($fh, 1024);
}
fclose($fh);
// send a copy of the email to your account
mail($email_addr, $subject, "Piped Email: ".$email_msg);
?>
Your mail server logs will probably say something about this. My guess is that it might be failing because your message is malformed because of the prefix you're adding. Try sending the message untouched, like this:
mail($email_addr, $subject, $email_msg);
Separately, for simple forwarding like this, you can probably set up your mail server to do this directly without having to go via a script.
There is no error checking in your script. There is no instrumentation in your script to see if it is even being run. You have not said why you believe that the script is being triggered. You have not said how mail() works on your test site.
Decompose the issues. Replace this script with one which dumps stein to a file to find out if there is an issue with the input integration.
Write and run a script which sends an email when using mail() when manually invoked. If you control the MTA then read your logs - even if these experiments are successful.
Then go back to your original script. Add some logging. Check the value returned by mail(). Check that the delivery path accepts forwarded mail with a broken envelope.

mailto function is not working with gmail address

How to send email from wamp/xampp localhost?
I have written the following simple code to send message.
I have already edited php.ini,sendmail.ini configuration files but no use,I can't receive email.I want to send message to any gmail address.I can sent email to my domain mail when this piece of code is uploaded via filezilla to my domain, but when I am giving to address as any gmail id, the code is not working.
<?php
$to = "bytecookiestest#gmail.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: swetha851991#gmail.com";
$s=mail($to,$subject,$txt,$headers);
if($s)
echo "success";
else
echo "failure";
?>
It's most likely a problem with the from-header you're sending. You're using your own Gmail-address to send mails from, but that also means you have to use the Google SMTP server. The credentials of swetha851991#gmail.com are the credentials you have to use to authenticate with the SMTP server. It'll otherwise be marked as spam.
Another option is to set the from-address to an address from the domain you're sending it from. If you domain is example.com, you can set the from-address to anything#example.com.

cant send mail through contact form in yahoo small business server. Do i need any configurations done before the program like smtp?

I want to host the form in yahoo small business server. Do I have to configure anything else other then coding in the hosting? New to the webhosting.
i know the program works good but it shows error because i think there is no proper connection.
please to help.
send_contact.php
<?php
// Contact subject
$subject ="$subject";
// Details
$message="$detail";
// Mail of sender
$mail_from="$customer_mail";
// From
$header="from: $name <$mail_from>";
// Enter your email address
$to ='';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information"
if($send_contact){
echo "We've received your contact information";
}
else {
echo "ERROR";
}
?>
Yahoo requires you to do some setting up before you can send mail via PHP. All of the steps are detailed here:
https://help.yahoo.com/kb/yahoo-web-hosting/SLN20671.html?impressions=true

having a php page send an email

This question should have a simple, simple answer, but I just can't seem to get it working. Here's the scenario:
I created a php page -> this one: http://adianl.ca/pages/member_application.php. Once the form is completed, it proceeds to http://adianl.ca/pages/member_application_action.php, puts the data into a MySQL db, & thanks the user for their interest. Anyway, the form works perfectly, except for one little thing: whenever someone fills out that form, I want an email to be sent to sbeattie#adianl.ca, informing them that the form was filled out, & the email would include the form components. The problem is, I can NOT get an email to be sent to that address, or any address truth be told. Having a php page send an email should be a simple thing to do, but it's really baffling me.
Can anyone help me with this? This particular problem has been troubling me since yesterday, & if anyone can help me with this...man, thank you soooooo much.
JP
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.adianl.ca"; // SMTP server $mail->From = "webadmin#adianl.ca";
$mail->FromName = "Web Administration [ADIANL]";
$mail->AddAddress("sbeattie#adianl.ca");
$mail->AddCC("justinwparsons#gmail.com"); the #messageBody variable is just a string
If you want to have the email sent using the server's sendmail client, you can use mail.
If you want it to use another mail server, there are extensions to connect to an SMTP server. I use PHPMailer.
If mail doesn't work, it could be that the server is not set up to send email, or it could be that the mail server is rejecting emails sent from php, amongst other reasons.
this code can also be used to email in php so have a look, you can find many more examples of emailing in php look around
?php
$to = "recipient#example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}

PHP sendmail not sending

I have a form that submits to PHP self. This script runs and says it is successful, but I do not receive an email.
if(isset($_POST['name']) and isset($_POST['email']) and isset($_POST['phone']))
{
//setup variables from input
$EMAIL = "anem#il.com";
$inEmail = $_POST['email'];
$subject = "Enquiry from ".$POST['name'];
$name = $_POST['name'];
//setup message
$message = "Enquiry from: ".$name."\nEmail: ".$inEmail."\nPhone: ".$phone."\n\nDeparture Date: ".$departureDate."\n\nreturnDate: ".$returnDate;
$message = wordwrap($message, 70);
//email enquiry details to site owner
if (mail($EMAIL, $subject, $message))
{
echo "Enquiry sent!";
} else
{
echo "fail!";
}
?>
The "Enquiry sent" message does appear.
I have postfix installed and I have also tried with sendmail installed. I have scanned local host using nmap and the smtp port is open.
Can anyone see any reason that the mail does not sent.
Check your mail log (usually /var/log/maillog). It would show the message arriving from PHP, and any delivery attempts/rejection notices from the MX of the receiver.
There a lot of possible reason that could explain why your email is sent and not received. Beside just setting up your SMTP server there are other things you need to do to make sure your email isn't just dropped before it reaches his destination.
You should take a look at this article that explains, what you should check :
http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html
In summary you need to :
Make sure the computer sending the email has a Reverse PTR record
Configure DomainKeys Identified Mail in your DNS and code
Set up a SenderID record in your DNS
Assuming that sendmail is working on your system, and that PHP is configured to use it correctly, try adding -f in the additional parameters, like this...
mail($EMAIL, $subject, $message, '-fYOURVALIDEMAILADDRESS#something.com'
This sets the envelope with a proper from address. See more on the PHP site: http://www.php.net/manual/en/function.mail.php#92528

Categories