Jump to content

Email script sending blank email


noerodaba

Recommended Posts

<section id="contact-page" class="container">
        <div class="row-fluid">


            <div class="span8">
                <h4>Contacto</h4>
                <div class="status alert alert-success" style="display: none"></div>


                <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
                  <div class="row-fluid">
                    <div class="span5">
                        <label>Nombre</label>
                        <input type="text" class="input-block-level" required placeholder="...">
                        <label>Asunto</label>
                        <input type="text" class="input-block-level" required placeholder="...">
                        <label>E-mail </label>
                        <input type="text" class="input-block-level" required placeholder="...">
                    </div>
                    <div class="span7">
                        <label>Mensaje</label>
                        <textarea name="message" id="message" required class="input-block-level" rows="8"></textarea>
                    </div>


                </div>
                <button type="submit" class="btn btn-primary btn-large pull-right">Enviar mensaje</button>
                <p> </p>


            </form>
        </div>

This above is the html form code I have .

 php email script I am using is below

<?php
	header('Content-type: application/json');
	$status = array(
		'type'=>'success',
		'message'=>'Su e-mail ha sido enviado. Nos pondremos en contacto con usted lo antes posible'
	);

    $name = @trim(stripslashes($_POST['Nombre'])); 
    $email = @trim(stripslashes($_POST['E-mail'])); 
    $subject = @trim(stripslashes($_POST['asunto'])); 
    $message = @trim(stripslashes($_POST['Mensaje'])); 

    $email_from = $email;
    $email_to = '[email protected]';

    $body = 'Nombre: ' . $name . "\n\n" . 'E-mail: ' . $email . "\n\n" . 'Asunto: ' . $subject . "\n\n" . 'Mensaje: ' . $message;

    $success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');

    echo json_encode($status);
    die;
	
	?>

Thats the code I am using for form . The javascript code is the following

jQuery(function($) {

	//Ajax contact
	var form = $('.contact-form');
		form.submit(function () {
			$this = $(this);
			$.post($(this).attr('action'),$(this).serialize(), function(data) {
			$this.prev().text(data.message).fadeIn().delay(3000).fadeOut();
		},'json');
		return false;
	});

	//Goto Top
	$('.gototop').click(function(event) {
		 event.preventDefault();
		 $('html, body').animate({
			 scrollTop: $("body").offset().top
		 }, 500);
	});	
	//End goto top		

});

I recieved the e-mail, but the content is blank.  I don´t find the mistake. Please help, I´m new student in this topic. Thanks you!!

Link to comment
https://forums.phpfreaks.com/topic/287437-email-script-sending-blank-email/
Share on other sites

I changed the name, but still got a blank mail

 <section id="contact-page" class="container">
        <div class="row-fluid">

            <div class="span8">
                <h4>Contacto</h4>
                <div class="status alert alert-success" style="display: none"></div>

                <form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
                  <div class="row-fluid">
                    <div class="span5">
                        <label>Nombre</label>
                        <input type="text" name="name" class="input-block-level" required placeholder="...">
                        <label>E-mail</label>
                        <input type="text" name="email" class="input-block-level" required placeholder="...">
                        <label>Asunto </label>
                        <input type="text" name="subject" class="input-block-level" required placeholder="...">
                    </div>
                    <div class="span7">
                        <label>Mensaje</label>
                        <textarea name="message" id="message" required class="input-block-level" rows="8"></textarea>
                    </div>

                </div>
                <button type="submit" class="btn btn-primary btn-large pull-right">Enviar mensaje</button>
                <p> </p>

            </form>
        </div>
<?php
	header('Content-type: application/json');
	$status = array(
		'type'=>'success',
		'message'=>'Su e-mail ha sido enviado. Nos pondremos en contacto con usted lo antes posible'
	);

    $name = @trim(stripslashes($_POST['name'])); 
    $email = @trim(stripslashes($_POST['email'])); 
    $subject = @trim(stripslashes($_POST['subject'])); 
    $message = @trim(stripslashes($_POST['message'])); 

    $email_from = $email;
    $email_to = '[email protected]';

    $body = 'name: ' . $name . "\n\n" . 'email: ' . $email . "\n\n" . 'subject: ' . $subject . "\n\n" . 'message: ' . $message;

    $success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');

    echo json_encode($status);
    die;
	
	?>

I don´t know where is the mistake.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.