ok i edited some of the code and the submit button does what i want it to do which is post my php file. However even if i get errors like i left a required field blank it will still submit the form now heres the new code i changed to
onSubmit: function(invalid, event) {
event.isDefaultPrevented();
if (invalid) {
} else {
$.post('save.php', this.$form.serialize(), function(response) {
// do something with response
}, 'json');
}
$('#invalid')
.show()
.toggleClass('valid', ! invalid)
.text(invalid ? (invalid +' invalid fields') : 'All good!');
}
});
How do i code this so that it only submits my form when there are no invalid fields
Dont use mail() function of php it will send your mail to junk only. Instead use SMTP php mailer function.
Why we should use SMTP instead PHP mail():
SMTP log in to an actual account on a mailserver and send the mail through SMTP to another mail server. If the mail server is configured correctly, your mails are sent from an actual account on a mailserver and will not wind up flagged as spam.
Mail sent with the mail() function is sent with sendmail in most cases. There is no authentication going on and it will almost always be flagged as spam if you use the "From:" in the extra headers.
This is because if you take a look at an original email file in say, gmail, you will see the headers that are sent. You are actually sending from user#serverhostname.tld and not someone#example.com like you had told the mail function to do.
If you use SMTP and view the original the email is actually sent from someone#example.com
You can download SMTP class from:
https://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/trunk/class.smtp.php?r=170
http://www.phpclasses.org/package/14-PHP-Sends-e-mail-messages-via-SMTP-protocol.html
have you tried just
mail($email_to, $email_subject, $email_message, $headers);
also declare all your variables at top of page
$email seems not to be declared
Related
I am using PHPMailer6.2.0 and I am having issues setting the return path.
I have added the custom header via PHPmailer function addCustomHeader()
$mail->addCustomHeader("Return-Path", $fromemail);
and for debugging I have printed out the header content in \PHPMailer\PHPMailer.php function mailSend($header, $body) on line 1794;
var_export($header);
die();
this prints out the header content before it will be sent and it verifies that the custom header return-path is set correctly, however in action, when i receive an email to my outlook, the header return path callbacks to the domains default email user#domain.com. Perhaps this is not the last place before the email is sent and it gets lost later on?
I am using DirectAdmin as my server manager
Stop right there! Senders should not set a return-path header. That header is added by the receiver, and what goes into it is dependent on the SMTP envelope sender, the address that's used in the SMTP MAIL FROM command that delivered the message. Setting this header as a sender is a straightforward contravention of the RFCs. So what should you do instead? Set the envelope sender, and in PHPMailer you do that like this:
$mail->Sender = $fromemail;
Even when you do this, whether the server your'e sending through will accept it is a different matter. For example gmail will not allow you to use anything other than your account username address or predefined aliases, not arbitrary addresses.
Have you seen the comment above in mailSend function?
The sender gets turned into a return-path header by the receiver!
<?php
$params = null;
//This sets the SMTP envelope sender which gets turned into a return-path header by the receiver
//A space after `-f` is optional, but there is a long history of its presence
//causing problems, so we don't use one
//Exim docs: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
//Sendmail docs: http://www.sendmail.org/~ca/email/man/sendmail.html
//Qmail docs: http://www.qmail.org/man/man8/qmail-inject.html
//Example problem: https://www.drupal.org/node/1057954
// CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
if (!empty($this->Sender) && static::validateAddress($this->Sender) && self::isShellSafe($this->Sender)) {
$params = sprintf('-f%s', $this->Sender);
}
I do not think you should set the return-path header by yourself. I believe PHPMailer uses the sender to handle this automatically. But correct me if i am wrong.
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
After calling the mail function I would like to get the complete mail message that I just sent. Not just the subject and content field but also auto generated information such as Date and Content-Transfer-Encoding. That is the entire message. How do I do that?
PHP doesn't actually send the mail, so it won't know about any of that. All the mail() function does is pass your stuff on to the sendmail binary (or whatever SMTP server you use instead) and return whether or not that was successful. The rest is up to the SMTP server.
Best suggestion I can offer is to have the mail BCCd to an account you control and parse the desired info from there.
I have noticed that some mails come with the from address like :
Adam Mannet via www.findyourfriend.com.
What headers do I need to pass to the native PHP mail() function to accomplish this when sending e-mail?
I think the via tag is added by the mail server when somebody uses an external (from his domain) smtp server.
Per example,
my email is iceduck#iceduck.net but I send email via Gmail's smtp, you will see From iceduck#iceduck.net via Gmail.com.
If you want to make the via appear then you'll have to send your mail through the smtp server you want to appear in the via.
You can check out this link : http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm
I don't think the solution is in the header.
Best
You should check PHP mail documentation. There is a description how to modify 'From' header. You should use additional_headers to change that header information and include 'friendly name' beside your e-mail address.
<?php
// The message
$message = "Message content";
$headers = 'From: User Name <user#example.com>';
// Send
mail('test#example.com', 'My Subject', $message, $headers);
?>
This should make your from address look like: 'User Name via www.example.com'
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>");
}