admin管理员组文章数量:1312953
My mail function is not working. When I submit form it says mail sent. But not receiving. I tried echo if the mail sent. It is also working. What is the issue here? Anything with mail function ?
<?php
$name = $_POST[ 'cuf_sender' . $n ];
$email = $_POST[ 'cuf_email' . $n ];
$subject = $this->o['subpre'] . ' ' . $_POST[ 'cuf_subject' . $n ];
$msg = $_POST[ 'cuf_msg' . $n ];
$extra = '';
foreach ( $_POST as $k => $f ) {
if ( strpos( $k, 'cuf_field_' ) !== false ) {
$extra .= $this->o[ substr( $k, 4, 7 ) ] . ": $f\r\n";
}
}
$headers =
"MIME-Version: 1.0\r\n" .
"Reply-To: \"$name\" <$email>\r\n" .
"Content-Type: text/plain; charset=\"" . get_settings( 'blog_charset' ) . "\"\r\n";
if ( ! empty( $from ) ) {
$headers .= "From: " . get_bloginfo( 'name' ) . " - $name <$from>\r\n";
} else if ( ! empty( $email ) ) {
$headers .= "From: " . get_bloginfo( 'name' ) . " - $name <$email>\r\n";
}
$fullmsg =
"Name: $name\r\n" .
"Email: $email\r\n" .
$extra . "\r\n" .
'Subject: ' . $_POST[ 'cuf_subject' . $n ] . "\r\n\r\n" .
wordwrap( $msg, 76, "\r\n" ) . "\r\n\r\n" .
'Referer: ' . $_SERVER['HTTP_REFERER'] . "\r\n" .
'Browser: ' . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
if ( wp_mail( $to, $subject, $fullmsg, $headers, $email ) ) {
echo $to;
exit();
My mail function is not working. When I submit form it says mail sent. But not receiving. I tried echo if the mail sent. It is also working. What is the issue here? Anything with mail function ?
<?php
$name = $_POST[ 'cuf_sender' . $n ];
$email = $_POST[ 'cuf_email' . $n ];
$subject = $this->o['subpre'] . ' ' . $_POST[ 'cuf_subject' . $n ];
$msg = $_POST[ 'cuf_msg' . $n ];
$extra = '';
foreach ( $_POST as $k => $f ) {
if ( strpos( $k, 'cuf_field_' ) !== false ) {
$extra .= $this->o[ substr( $k, 4, 7 ) ] . ": $f\r\n";
}
}
$headers =
"MIME-Version: 1.0\r\n" .
"Reply-To: \"$name\" <$email>\r\n" .
"Content-Type: text/plain; charset=\"" . get_settings( 'blog_charset' ) . "\"\r\n";
if ( ! empty( $from ) ) {
$headers .= "From: " . get_bloginfo( 'name' ) . " - $name <$from>\r\n";
} else if ( ! empty( $email ) ) {
$headers .= "From: " . get_bloginfo( 'name' ) . " - $name <$email>\r\n";
}
$fullmsg =
"Name: $name\r\n" .
"Email: $email\r\n" .
$extra . "\r\n" .
'Subject: ' . $_POST[ 'cuf_subject' . $n ] . "\r\n\r\n" .
wordwrap( $msg, 76, "\r\n" ) . "\r\n\r\n" .
'Referer: ' . $_SERVER['HTTP_REFERER'] . "\r\n" .
'Browser: ' . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
if ( wp_mail( $to, $subject, $fullmsg, $headers, $email ) ) {
echo $to;
exit();
Share
Improve this question
edited Apr 11, 2014 at 12:11
Subharanjan
1,5891 gold badge17 silver badges29 bronze badges
asked Apr 11, 2014 at 10:30
Joel JamesJoel James
1171 silver badge11 bronze badges
6
- 1 Even if the mail gets send from the system, there is no guarantee that the mail will get delivered !! Check with your SMTP. May be you can use some SMTP Configure plugin and try with different SMTPs. – Subharanjan Commented Apr 11, 2014 at 11:34
- Please suggest one plugin – Joel James Commented Apr 11, 2014 at 11:36
- WP SMTP, WP Mail SMTP Try configuring with gmail server as the SMTP. :) – Subharanjan Commented Apr 11, 2014 at 11:38
- @SpamBox What is $to value? – Rajeev Vyas Commented Apr 11, 2014 at 11:43
- $to is defined already. I din't include that in question – Joel James Commented Apr 11, 2014 at 11:50
2 Answers
Reset to default 1You are passing $email
where there should be attachments. Look at wp_mail arguments.
Also you have not defined $to
variable which in your case i assume should be $email
.
Try this,
$name = $_POST['cuf_sender'.$n];
$email = $_POST['cuf_email'.$n];
$subject= $this->o['subpre'].' '.$_POST['cuf_subject'.$n];
$msg = $_POST['cuf_msg'.$n];
$extra = '';
foreach ($_POST as $k => $f )
if ( strpos( $k, 'cuf_field_') !== false )
$extra .= $this->o[substr($k, 4, 7)].": $f\r\n";
$headers =
"MIME-Version: 1.0\r\n".
"Reply-To: \"$name\" <$email>\r\n".
"Content-Type: text/plain; charset=\"".get_settings('blog_charset')."\"\r\n";
if ( !empty($from) )
$headers .= "From: ".get_bloginfo('name')." - $name <$from>\r\n";
else if ( !empty($email) )
$headers .= "From: ".get_bloginfo('name')." - $name <$email>\r\n";
$fullmsg =
"Name: $name\r\n".
"Email: $email\r\n".
$extra."\r\n".
'Subject: '.$_POST['cuf_subject'.$n]."\r\n\r\n".
wordwrap($msg, 76, "\r\n")."\r\n\r\n".
'Referer: '.$_SERVER['HTTP_REFERER']."\r\n".
'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
if ( wp_mail( $email, $subject, $fullmsg, $headers) )
{
echo $to;
exit();
In addition to the other suggestions, make sure that the 'from' email address is an email address that belongs to the domain of your site, and that it exists.
Some hosts will not send mail from the example domain when the 'from' address is '[email protected]'. They will sense that as a 'mail relay', which is what spammers will try, so will block the mail.
Note that the return value of the mail() function is just a flag that shows that the message was successfully/unsuccessfully sent to the mail server. It is not an indication that the mail was actually sent.
本文标签: emailMail function is not working
版权声明:本文标题:email - Mail function is not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741896141a2403586.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论