A HREF MAILTO ONCLICK CLOSE WINDOW

function enter_complete()
{
alert("Email has been sent.");
window.close();
return true;
}
<a href= "mailto: $mailto & $subject & $body" >E-Mail Customers </a>

<a href= "mailto: $mailto&subject&body" onClick="enter_complete()">E-Mail Customers </a>

The first link works creating the email.
The second link does not create the email, but does close the window.

I have tried adding a delay, but that makes no difference.

How do I create this to launch the email and then close the window instead of just closing the window?

Thank you

Joe


Source: stackoverflow-php

change laravel 5.4 text mail content-type to text/plain

I am sending a small text mail with laravel:

public function build()
{
    return $this->text('emails.empty')->subject($this->msg)
                ->with('msg',$this->msg);
}

The view empty.blade.php should only print the message:

{{ $msg }}

But neomutt receives text/html content:

[-- text/html wird nicht unterst├╝tzt ('v' benutzen, um diesen Teil anzuzeigen) --]

and thunderbird also shows text/html instead of plain text:

MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

What can I do to get the mail so that neomutt does not complain?
I guess I need text/plain.


Source: stackoverflow-php

Email validation using PHP

I have a form for which i am trying to validate the email address. If the email address is incorrect i want a value of “Please type a valid email address.” to be returned into the “email” input box on the form. What am i doing wrong? No validation is taking place. I receive the form information at my email and once submitted the user is sent to the “Thank you” page, but no validation. I can put anything in the “email” input and the form will submit.

<form action="../php/contact.php" method="post">
  <p>First Name:</p>
   <input class="box_style" type="text" name="first_name" required maxlength="20" />

  <p>Last Name:</p>
   <input class="box_style" type="text" name="last_name" required maxlength="25" />

  <p>Email:</p>
   <input class="box_style" type="text" name="email" required maxlength="50" />

   <p>Contact Number (optional):</p>
   <input class="box_style" type="text" name="contact_number" maxlength="12" />

  <p>How did you find us?</p>
  <select class="box_style" name="how" required>
    <option value="choose">Select...</option>
    <option value="referal">Referal</option>
    <option value="website">Website</option>
    <option value="search">Search Engine</option>
    <option value="card">Business Card</option>
 </select> 

 <p>Enquiries:</p> 
  <textarea class="box_style" name="inquiries" cols="30" rows="10"></textarea>

  <input class="box_style" type="submit" name="submit" value="Submit"/>   
 </form>

and this is the php

<?php

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

// define variables and set to empty values
$fName = $lName = $email = $cNum = $how =  $enquiries = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") { 
$fName = test_input($_POST["first_name"]);
$lName = test_input($_POST["last_name"]);
$cNum = test_input($_POST["contact_number"]);
$how = test_input($_POST["how"]);
$enquiries = test_input($_POST["enquiries"]);

$email = test_input($_POST["email"]);
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    print  "<p>Please type a valid email address.</p>";

header("Location: www.mysite/thankyou.com");
}};

$email_from = 'my@email.com';
$email_subject = "New Inquiry";
$email_body = "You have received a new message from" ." ". "$fName" ." ".    "$lName" ."n".
"$inquiries"."n".
"Referal Type:" ." ". "$how" ."n".
"Contact Number:" ." ". "$cNum" ."n";

$to = "my@email.com";
$headers = "From: $email_from rn";
$headers .= "Reply-To: $email rn";
mail($to,$email_subject,$email_body,$headers);


?>

Thank You


Source: stackoverflow-php

Cron job doesn’t send email

I have a cron job set up on my hostgator server that returns a value of 1 (email sent), but doesn’t actually send the email. When I call the php file manually in the browser, the email gets sent. It doesn’t if run via cron.

Earlier this month, I moved my site from one server on hostgator to another server (on hostgator) so I could get SSL and a dedicated IP address. Since moving the site, the cron jobs work OK except for the part that sends the email (ie, database functions work fine). I’ve contacted hostgator tech support, but he thinks the problem is in my code.

Thinking that maybe my server info was incorrect, I switched to using smtp.gmail.com and using a gmail account to send the mail, but that didn’t work either. Please help!

The cron job is set up like this:

* 7 * * * /opt/php56/bin/php /home/user/public_html/somefolder/sendmailcron.php

(While testing, I changed it to run every 2 minutes: */2 * * * * )

Here’s the sendmailcron.php script:

<?php

$now = date("Y-m-d H:i:s");

$msgcontent = [];
$msgcontent['email'] = "recipient@example.com";
$msgcontent['name'] = "Recipient Name";
$msgcontent['textpart'] = "This is the text version of the email body.";
$msgcontent['htmlpart'] = "<p>This is the <strong>HTML</strong> version of the email body.</p>";
$msgcontent['subject'] = "Test email sent at " . $now;

$result = sendMyMail($msgcontent, "HTML");
exit();    

function sendMyMail($msgcontent, $format="HTML") {
    require_once '/home/user/public_html/somefolder/swiftmailer/lib/swift_required.php';

    $result = 0;
    $subject = $msgcontent['subject'];
    $email   = $msgcontent['email'];
    if (strlen($email) == 0) {
        return 0;
    }
    $name = $msgcontent['name'];

    $emailbody = $msgcontent['textpart'];
    $emailpart = $msgcontent['htmlpart'];

    switch($format) {
        case "TEXT":
            $msgformat = 'text/plain';
            break;
        case "HTML":
            $msgformat = 'text/html; charset=UTF-8';
            break;
        default:
            $msgformat = 'text/html';
            break;
    }

    $adminemailaddress = "me@mydomain.com";
    $adminemailpwd     = 'myadminpwd';
    $sendername        = 'My Real Name';

    $transport = Swift_SmtpTransport::newInstance('mygator1234.hostgator.com', 465, "ssl")
      ->setUsername($adminemailaddress)
      ->setPassword($adminemailpwd)
      ; 

    $mailer = Swift_Mailer::newInstance($transport);

    // Create the message
    if($format == "TEXT") {
        $message = Swift_Message::newInstance($subject)
            ->setFrom(array($adminemailaddress => $sendername))
            ->setTo(array($email => $name))
            ->setBody($emailbody)
            ->setContentType($msgformat)
          ;  
    }

    else {
        $message = Swift_Message::newInstance($subject)
            ->setFrom(array($adminemailaddress => $sendername))
            ->setTo(array($email => $name))
            ->setBody($emailpart)
            ->setContentType($msgformat)
          ;  
    }

    //This is where we send the email
    try {
        $result = $mailer->send($message); //returns the number of messages sent
    } catch(Swift_TransportException $e){
        $response = $e->getMessage() ;
    }
    return $result; //will be 1 if success or 0 if fail
}

?>

The return value is always 1, but no email is sent.

Any suggestions would be greatly appreciated!


Source: stackoverflow-php

Extract URL from order note and add it only to order completed email in Woocommerce

I’ve searched around here and some posts helped me almost nailing this problem:

My parcel company adds an order note to the order including text and an tracking url for the package. And after that they put the order on completed.

This URL needs to be added to the order completed mail to the customer.

This code is working but only if I send the order completed mail manually:

add_action( 'woocommerce_email_before_order_table', 'woo_add_order_notes_to_email' );
function woo_add_order_notes_to_email() {
    global $woocommerce, $post;
    $args = array(
        'post_id'   => $post->ID,
        'status'    => 'approve',
        'type'      => 'order_note'
    );
    $notes = get_comments( $args );


    if ( $notes ) {
        foreach( $notes as $note ) {
            $notecontent = $note->comment_content;

            if( preg_match('/[a-zA-Z]+://[0-9a-zA-Z;./?:@=_#&%~,+$-]+/', $notecontent, $matches) != 0 ) {

                echo '<p>You can follow your order via this link: <a href = "' . $matches[0] . '">' . $matches[0] . '</a></p>';

            }


        }
    }

}

I hope you guys can help me out.


Source: stackoverflow-php